-
-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Meteor v3 #309
[WIP] Meteor v3 #309
Conversation
I'm have this wrapped up for Meteor 3 just have to do some minor updates to before and after callbacks being async, but there are some important things to discuss before I continue to work on this. I hope we agree that after & before should now be async functions, as discussed here: #308 Then we have this issue about async/sync methods: #302 If before/after hooks are async, that means that all wrappers that this package will provide will be async, too. For example, with async insert wrapper we have this issue if (Meteor.isClient) {
Tinytest.onlyAsync('insert - local collection sync insert', async function (test, next) {
const collection = new Mongo.Collection(null)
const tmp = {}
collection.before.insert(function (userId, doc) {
tmp.typeof_userId = typeof userId
doc.before_insert_value = true
})
InsecureLogin.ready(function () {
// Since insert.js is now async because it supports before/after being async, we wrap the sync insert()
// method but return the promise!
const res = collection.insert({ start_value: true }, (err, res) => {
// This works ok
test.equal(typeof res, 'string', 'Callback value must be string')
console.log('res', res)
next()
})
// This fails, return value is a promise.
test.equal(typeof res, 'string', 'Return value must be string')
})
})
} We obviously cannot do that since it changes Meteor's interface. Some options that came to my mind Option 1: separate sync and async callbacksWe could keep sync and async versions of all methods (insert, update, etc) and have sync & async versions of before and after callbacks. const collection = new Mongo.Collection(null)
collection.before.insert(function syncFn() {});
collection.before.insertAsync(async function() {});
// Uses only sync callbacks
collection.insert({});
// Uses both sync & async callbacks
collection.insertAsync({}); Good:
Bad:
Option 2: hooks to run only on async callsGood:
Bad:
Let me know if you have other ideas on how to solve this. |
In my opinion, option 2 (providing hooks only for async versions) is the way to go, as sync versions of the collection calls should disappear very quickly of our apps as we migrate to meteor 3 |
Option 2 will be better, but also allowing hooking sync methods. This will make it not backwards compatible, but in a more compatible way while there is migration to async methods. This will also fix #301. |
Yeah, I'd prefer option 2. What's the status of this PR? Can you include the option and release a beta soon? We actually chose to do something similar for both ostrio:files and collection2 completely dropping support for sync functions. |
Ok, looks like it will be option #2. The last question if whether we rename the methods to I think I can have this ready for start of next week. |
@bhunjadi Great work! +1 from me too for option 2. |
Hello, I am testing meteor 3 rc.0 with collection hook, they are not triggered : example repo : https://github.com/dokithonon/meteor-test-async/tree/3.0-rc.0 Is this PR will fix this ? Thanks a lot |
Going with option #2 seems reasonable. There is one problem, though. Patching a cursor returned from find() is not ideal. @dokithonon Yes, this PR should fix it. |
Option 2 it will have to be. The use case is that the hook is tied to action, not to a/sync execution. For Meteor 3, the sync executions can be left only to the client as on server everything is async. |
I'll have to do some updates regarding the sync functions that work on the client. Currently we hook into them also and they become async which is not desired. |
Alright! This has become a major blocker for me in Meteor 3 adoption, but I'm just starting to learn about the code, still let me know if I can help in any way. Also I'll be happy to publish any updates under the beta tag. |
@bhunjadi hey, thank you for your work. What is the current state? |
I don't want to back-pedal on my promise but I'm looking into this package right now and figuring out how to continue @bhunjadi great work, wish me good luck boys 😄 |
Just to clarify that I'll probably be able to invest some of my time this week into this package. |
@bhunjadi I know how intensive and underappreciated open source work can be yet this package needs to be made async asap so would you be able to dedicate more time even if if you weren't able to wrap it up this week? Basically we need someone dedicated to fix this problem and not one and off. Let me assert again this isn't to undermine your efforts of what you've done so far. You've done great work that we all look up to and appreciate. It's just we need a dedicated person time-wise to wrap this up and get it over with. EDIT: I'll probably carry it over from here regardless as this is blocking our app update! |
Ok, I have some uncommited changes and I'll try to figure out if I can push these. You can then merge these if there woould be a need to do it. So, to summarize the issues I'm aware of:
@kolyasya |
We can do a v2 with breaking changes for Meteor 3. These would be that we won't deal with sync collections calls on the client and we can drop support for the find hook due to the breaking changes in async in Meteor 3. |
As for the beta that is from the other branch which only help you to resolve the dependencies when upgrading to Meteor 3, nothing else really. |
@bhunjadi yeah, sorry, with the files from PR hooks seem to work for me. |
I pushed the changes related to our discussions above. The tests are passing locally in watch mode, but when using --once they're still stuck so I expect the pipeline will fail. Can we publish this as 2.0.0 alpha maybe? Breaking changes
For 1) we can introduce sync hooks.
|
What do you mean by "breaking" cannot the cursor values be promisified so later processes can be run on it? |
If we just re-use the logic from before, find() method will become async, meaning it would have to be used like If you look at the code, find() wrapper allows hooks to change selector and options and then passes these modified values into the wrapped find(). One possible workaround I can think of is that we patch the cursor's fetchAsync, countAsync and so on. const cursor = _super.call(this, selector, options)
patchCursor(cursor)
return cursor
|
Hello,
I was having a similar problem
https://forums.meteor.com/t/meteor-3-0-beta-7-is-out/61417/3
Thomas Doki-Thonon
…On Thu, May 23, 2024, 10:09 Jan Dvorak ***@***.***> wrote:
Testing this out, so far so good, but when running with
audit-argument-checks I get the Error: Did not check() all arguments
during publisher. Looking at the stack trace:
W20240523-09:58:39.726(2)? (STDERR) errorClass [Error]: Match error: Expected string, got null
W20240523-09:58:39.726(2)? (STDERR) at format (packages/check/match.js:11:15)
W20240523-09:58:39.726(2)? (STDERR) at check (packages/check/match.js:53:13)
W20240523-09:58:39.726(2)? (STDERR) at Subscription.<anonymous> (server/publications/profiles.ts:110:2)
W20240523-09:58:39.727(2)? (STDERR) at packages/matb33:collection-hooks/server.js:33:71
W20240523-09:58:39.727(2)? (STDERR) at EnvironmentVariableAsync.<anonymous> (packages/meteor.js:1288:23)
W20240523-09:58:39.727(2)? (STDERR) at packages/meteor.js:757:17
W20240523-09:58:39.727(2)? (STDERR) at AsyncLocalStorage.run (node:async_hooks:346:14)
W20240523-09:58:39.727(2)? (STDERR) at Object.Meteor._runAsync (packages/meteor.js:754:28)
W20240523-09:58:39.727(2)? (STDERR) at EnvironmentVariableAsync.withValue (packages/meteor.js:1282:19)
W20240523-09:58:39.727(2)? (STDERR) at Subscription._handler (packages/matb33:collection-hooks/server.js:33:26)
W20240523-09:58:39.727(2)? (STDERR) at packages/check/match.js:130:15
W20240523-09:58:39.727(2)? (STDERR) at EnvironmentVariableAsync.<anonymous> (packages/meteor.js:1288:23)
W20240523-09:58:39.727(2)? (STDERR) at packages/meteor.js:757:17
W20240523-09:58:39.728(2)? (STDERR) at AsyncLocalStorage.run (node:async_hooks:346:14)
W20240523-09:58:39.728(2)? (STDERR) at Object.Meteor._runAsync (packages/meteor.js:754:28)
W20240523-09:58:39.728(2)? (STDERR) at EnvironmentVariableAsync.withValue (packages/meteor.js:1282:19)
W20240523-09:58:39.728(2)? (STDERR) at Object._failIfArgumentsAreNotAllChecked (packages/check/match.js:128:43)
W20240523-09:58:39.728(2)? (STDERR) at maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1988:18)
W20240523-09:58:39.728(2)? (STDERR) at DDP._CurrentPublicationInvocation.withValue.name (packages/ddp-server/livedata_server.js:1184:11)
W20240523-09:58:39.728(2)? (STDERR) at EnvironmentVariableAsync.<anonymous> (packages/meteor.js:1288:23)
W20240523-09:58:39.728(2)? (STDERR) at packages/meteor.js:757:17
I think we might have something going on line 33 of server.js which might
cause the package to misidentify the checks.
Or maybe I got this completely wrong. Still looking at the file, do we
still need it? userId has been added to publications in core a long time
ago, or is there something more to it?
—
Reply to this email directly, view it on GitHub
<#309 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAOFI7VVMAJRS33NF3FTLD3ZDWP43AVCNFSM6AAAAABDYZYGZCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMRWGQ4TENRRGE>
.
You are receiving this because you were mentioned.Message ID:
<Meteor-Community-Packages/meteor-collection-hooks/pull/309/c2126492611@
github.com>
|
Hello, I have just tested this PR in our project. We use only before.insert/update/remove and after.insert/update/remove (we do not use hooks on find and findOne). This seems to be working perfectly. Discussions are on the find and findOne command right ? |
Alright! I'm going to publish the current state as a beta shortly. |
df6988a
into
Meteor-Community-Packages:migrate/3.0
@bhunjadi I was unable to push to your branch, so I pushed it to this repo's migration branch. |
See #306 |
|
@bhunjadi could you please prepare a changelog of work done so far, so that people know what to expect? I will create a 2.0.0 part in the history file shortly, so that you can make a nice PR against it (plus include any other improvements that you have). |
Ok, will do. I'll see if I can do anything about |
Update:
Question: do you want me to open a separate PR with the latest changes? The draft version of changelog would be something like: SummaryAdded support for Meteor 3.0 and made all hooks async. Breaking changes
@harryadel Did you fork this repo and go with your own implementation? Did you add any new features? |
No new features were added, I merely monkey patched things to get things working ASAP. I might revert and use your fork if it's better done. Thank you for your efforts @bhunjadi |
@bhunjadi please do a new PR against |
I started working on this since I was stuck when updating grapher (PR: cult-of-coders/grapher#484)
I have one test failing right now for Meteor v3. I'll also have to test with Meteor v2.
Current state:
Other comments:
--once
with TinyTest, it just hangs waiting withApp running at: http://localhost:3025/
Testing with Meteor 2.15 for v2. I still have 8 errors that I have to check.We won't support Meteor 2 with this release.[Update]
I cannot figure out failing test for Meteor 3.0. Maybe it might be a bug there: meteor/meteor#13036
[Update 2]
Fixed the test for v3, it appears it is expected behavior in Meteor v3, but might be fixed in the future (meteor/meteor#13052 (comment))
[Update 3]
Made all before and after hooks async except find(), meaning that we'll be awaiting them before calling the original method or before returning results.
Basically:
Before and after hooks are triggered in order they were added. This reflects the old behavior.
If this is not desired, we could trigger them simultaneously or add an option for caller to define how should they be handled - all at once or one by one.
find()
has its own problems, if we allow before/after hooks directly it means we'll have to awaitfind()
which we cannot do. Alternatives are patching (wrapping) returned cursor methods (fetchAsync, countAsync) and use the after/before hooks there.There are also some issues with Meteor v2.13 tests that I have to figure out.The problem with Meteor v2 and async approach is that in
accounts-base/accounts_server.js
we have this codeAlso, I cannot make
meteor test-packages --once
work at all.This is the result: