@decocms/blocks 8.1.0-next.1 → 8.1.0-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/deco.js +5 -12
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol/assets.d.ts +46 -0
- package/dist/protocol/assets.d.ts.map +1 -0
- package/dist/protocol/assets.js +105 -0
- package/dist/protocol/assets.js.map +1 -0
- package/dist/protocol/canonical.d.ts +8 -0
- package/dist/protocol/canonical.d.ts.map +1 -0
- package/dist/protocol/canonical.js +8 -0
- package/dist/protocol/canonical.js.map +1 -0
- package/dist/protocol/ciphertext.d.ts +7 -0
- package/dist/protocol/ciphertext.d.ts.map +1 -0
- package/dist/protocol/ciphertext.js +7 -0
- package/dist/protocol/ciphertext.js.map +1 -0
- package/dist/protocol/client.d.ts +54 -0
- package/dist/protocol/client.d.ts.map +1 -0
- package/dist/protocol/client.js +104 -0
- package/dist/protocol/client.js.map +1 -0
- package/dist/protocol/conformance/cases/assets.d.ts +3 -0
- package/dist/protocol/conformance/cases/assets.d.ts.map +1 -0
- package/dist/protocol/conformance/cases/assets.js +71 -0
- package/dist/protocol/conformance/cases/assets.js.map +1 -0
- package/dist/protocol/conformance/cases/guards.d.ts +3 -0
- package/dist/protocol/conformance/cases/guards.d.ts.map +1 -0
- package/dist/protocol/conformance/cases/guards.js +265 -0
- package/dist/protocol/conformance/cases/guards.js.map +1 -0
- package/dist/protocol/conformance/cases/reads.d.ts +3 -0
- package/dist/protocol/conformance/cases/reads.d.ts.map +1 -0
- package/dist/protocol/conformance/cases/reads.js +140 -0
- package/dist/protocol/conformance/cases/reads.js.map +1 -0
- package/dist/protocol/conformance/cases/types.d.ts +9 -0
- package/dist/protocol/conformance/cases/types.d.ts.map +1 -0
- package/dist/protocol/conformance/cases/types.js +2 -0
- package/dist/protocol/conformance/cases/types.js.map +1 -0
- package/dist/protocol/conformance/cases/wire.d.ts +3 -0
- package/dist/protocol/conformance/cases/wire.d.ts.map +1 -0
- package/dist/protocol/conformance/cases/wire.js +130 -0
- package/dist/protocol/conformance/cases/wire.js.map +1 -0
- package/dist/protocol/conformance/cases/writes.d.ts +3 -0
- package/dist/protocol/conformance/cases/writes.d.ts.map +1 -0
- package/dist/protocol/conformance/cases/writes.js +278 -0
- package/dist/protocol/conformance/cases/writes.js.map +1 -0
- package/dist/protocol/conformance/contentHashFixtures.d.ts +51 -0
- package/dist/protocol/conformance/contentHashFixtures.d.ts.map +1 -0
- package/dist/protocol/conformance/contentHashFixtures.js +94 -0
- package/dist/protocol/conformance/contentHashFixtures.js.map +1 -0
- package/dist/protocol/conformance/context.d.ts +100 -0
- package/dist/protocol/conformance/context.d.ts.map +1 -0
- package/dist/protocol/conformance/context.js +155 -0
- package/dist/protocol/conformance/context.js.map +1 -0
- package/dist/protocol/conformance/index.d.ts +32 -0
- package/dist/protocol/conformance/index.d.ts.map +1 -0
- package/dist/protocol/conformance/index.js +90 -0
- package/dist/protocol/conformance/index.js.map +1 -0
- package/dist/protocol/errors.d.ts +85 -0
- package/dist/protocol/errors.d.ts.map +1 -0
- package/dist/protocol/errors.js +62 -0
- package/dist/protocol/errors.js.map +1 -0
- package/dist/protocol/index.d.ts +28 -0
- package/dist/protocol/index.d.ts.map +1 -0
- package/dist/protocol/index.js +28 -0
- package/dist/protocol/index.js.map +1 -0
- package/dist/protocol/keys.d.ts +101 -0
- package/dist/protocol/keys.d.ts.map +1 -0
- package/dist/protocol/keys.js +223 -0
- package/dist/protocol/keys.js.map +1 -0
- package/dist/protocol/params.d.ts +10 -0
- package/dist/protocol/params.d.ts.map +1 -0
- package/dist/protocol/params.js +54 -0
- package/dist/protocol/params.js.map +1 -0
- package/dist/protocol/secrets.d.ts +22 -0
- package/dist/protocol/secrets.d.ts.map +1 -0
- package/dist/protocol/secrets.js +200 -0
- package/dist/protocol/secrets.js.map +1 -0
- package/dist/protocol/server/assets.d.ts +20 -0
- package/dist/protocol/server/assets.d.ts.map +1 -0
- package/dist/protocol/server/assets.js +77 -0
- package/dist/protocol/server/assets.js.map +1 -0
- package/dist/protocol/server/auth.d.ts +31 -0
- package/dist/protocol/server/auth.d.ts.map +1 -0
- package/dist/protocol/server/auth.js +32 -0
- package/dist/protocol/server/auth.js.map +1 -0
- package/dist/protocol/server/bodyCache.d.ts +28 -0
- package/dist/protocol/server/bodyCache.d.ts.map +1 -0
- package/dist/protocol/server/bodyCache.js +75 -0
- package/dist/protocol/server/bodyCache.js.map +1 -0
- package/dist/protocol/server/content.d.ts +44 -0
- package/dist/protocol/server/content.d.ts.map +1 -0
- package/dist/protocol/server/content.js +132 -0
- package/dist/protocol/server/content.js.map +1 -0
- package/dist/protocol/server/core.d.ts +63 -0
- package/dist/protocol/server/core.d.ts.map +1 -0
- package/dist/protocol/server/core.js +77 -0
- package/dist/protocol/server/core.js.map +1 -0
- package/dist/protocol/server/handler.d.ts +5 -0
- package/dist/protocol/server/handler.d.ts.map +1 -0
- package/dist/protocol/server/handler.js +70 -0
- package/dist/protocol/server/handler.js.map +1 -0
- package/dist/protocol/server/http.d.ts +24 -0
- package/dist/protocol/server/http.d.ts.map +1 -0
- package/dist/protocol/server/http.js +133 -0
- package/dist/protocol/server/http.js.map +1 -0
- package/dist/protocol/server/index.d.ts +11 -0
- package/dist/protocol/server/index.d.ts.map +1 -0
- package/dist/protocol/server/index.js +9 -0
- package/dist/protocol/server/index.js.map +1 -0
- package/dist/protocol/server/methods/apply.d.ts +4 -0
- package/dist/protocol/server/methods/apply.d.ts.map +1 -0
- package/dist/protocol/server/methods/apply.js +275 -0
- package/dist/protocol/server/methods/apply.js.map +1 -0
- package/dist/protocol/server/methods/read.d.ts +14 -0
- package/dist/protocol/server/methods/read.d.ts.map +1 -0
- package/dist/protocol/server/methods/read.js +132 -0
- package/dist/protocol/server/methods/read.js.map +1 -0
- package/dist/protocol/server/rpc.d.ts +7 -0
- package/dist/protocol/server/rpc.d.ts.map +1 -0
- package/dist/protocol/server/rpc.js +115 -0
- package/dist/protocol/server/rpc.js.map +1 -0
- package/dist/protocol/storage/fs/hash.d.ts +8 -0
- package/dist/protocol/storage/fs/hash.d.ts.map +1 -0
- package/dist/protocol/storage/fs/hash.js +20 -0
- package/dist/protocol/storage/fs/hash.js.map +1 -0
- package/dist/protocol/storage/fs/index.d.ts +30 -0
- package/dist/protocol/storage/fs/index.d.ts.map +1 -0
- package/dist/protocol/storage/fs/index.js +301 -0
- package/dist/protocol/storage/fs/index.js.map +1 -0
- package/dist/protocol/storage/fs/lock.d.ts +8 -0
- package/dist/protocol/storage/fs/lock.d.ts.map +1 -0
- package/dist/protocol/storage/fs/lock.js +61 -0
- package/dist/protocol/storage/fs/lock.js.map +1 -0
- package/dist/protocol/storage/fs/transaction.d.ts +19 -0
- package/dist/protocol/storage/fs/transaction.d.ts.map +1 -0
- package/dist/protocol/storage/fs/transaction.js +174 -0
- package/dist/protocol/storage/fs/transaction.js.map +1 -0
- package/dist/protocol/storage/fs/unsupported.d.ts +10 -0
- package/dist/protocol/storage/fs/unsupported.d.ts.map +1 -0
- package/dist/protocol/storage/fs/unsupported.js +4 -0
- package/dist/protocol/storage/fs/unsupported.js.map +1 -0
- package/dist/protocol/storage/memory.d.ts +40 -0
- package/dist/protocol/storage/memory.d.ts.map +1 -0
- package/dist/protocol/storage/memory.js +179 -0
- package/dist/protocol/storage/memory.js.map +1 -0
- package/dist/protocol/storage.d.ts +178 -0
- package/dist/protocol/storage.d.ts.map +1 -0
- package/dist/protocol/storage.js +29 -0
- package/dist/protocol/storage.js.map +1 -0
- package/dist/protocol/types.d.ts +194 -0
- package/dist/protocol/types.d.ts.map +1 -0
- package/dist/protocol/types.js +31 -0
- package/dist/protocol/types.js.map +1 -0
- package/dist/v8/analytics.d.ts +31 -0
- package/dist/v8/analytics.d.ts.map +1 -0
- package/dist/v8/analytics.js +46 -0
- package/dist/v8/analytics.js.map +1 -0
- package/dist/v8/background.d.ts +26 -0
- package/dist/v8/background.d.ts.map +1 -0
- package/dist/v8/background.js +95 -0
- package/dist/v8/background.js.map +1 -0
- package/dist/v8/builtins/data.d.ts +15 -0
- package/dist/v8/builtins/data.d.ts.map +1 -0
- package/dist/v8/builtins/data.js +18 -0
- package/dist/v8/builtins/data.js.map +1 -0
- package/dist/v8/builtins/index.d.ts +9 -0
- package/dist/v8/builtins/index.d.ts.map +1 -0
- package/dist/v8/builtins/index.js +24 -0
- package/dist/v8/builtins/index.js.map +1 -0
- package/dist/v8/builtins/lazy.d.ts +17 -0
- package/dist/v8/builtins/lazy.d.ts.map +1 -0
- package/dist/v8/builtins/lazy.js +13 -0
- package/dist/v8/builtins/lazy.js.map +1 -0
- package/dist/v8/builtins/legacy.d.ts +41 -0
- package/dist/v8/builtins/legacy.d.ts.map +1 -0
- package/dist/v8/builtins/legacy.js +62 -0
- package/dist/v8/builtins/legacy.js.map +1 -0
- package/dist/v8/builtins/matchers.d.ts +19 -0
- package/dist/v8/builtins/matchers.d.ts.map +1 -0
- package/dist/v8/builtins/matchers.js +24 -0
- package/dist/v8/builtins/matchers.js.map +1 -0
- package/dist/v8/builtins/multivariate.d.ts +15 -0
- package/dist/v8/builtins/multivariate.d.ts.map +1 -0
- package/dist/v8/builtins/multivariate.js +18 -0
- package/dist/v8/builtins/multivariate.js.map +1 -0
- package/dist/v8/builtins/secret.d.ts +7 -0
- package/dist/v8/builtins/secret.d.ts.map +1 -0
- package/dist/v8/builtins/secret.js +68 -0
- package/dist/v8/builtins/secret.js.map +1 -0
- package/dist/v8/canonical.d.ts +70 -0
- package/dist/v8/canonical.d.ts.map +1 -0
- package/dist/v8/canonical.js +130 -0
- package/dist/v8/canonical.js.map +1 -0
- package/dist/v8/ciphertext.d.ts +58 -0
- package/dist/v8/ciphertext.d.ts.map +1 -0
- package/dist/v8/ciphertext.js +134 -0
- package/dist/v8/ciphertext.js.map +1 -0
- package/dist/v8/cli/builtins.d.ts +11 -0
- package/dist/v8/cli/builtins.d.ts.map +1 -0
- package/dist/v8/cli/builtins.js +18 -0
- package/dist/v8/cli/builtins.js.map +1 -0
- package/dist/v8/cli/check/index.d.ts +41 -0
- package/dist/v8/cli/check/index.d.ts.map +1 -0
- package/dist/v8/cli/check/index.js +713 -0
- package/dist/v8/cli/check/index.js.map +1 -0
- package/dist/v8/cli/check/messages.d.ts +24 -0
- package/dist/v8/cli/check/messages.d.ts.map +1 -0
- package/dist/v8/cli/check/messages.js +150 -0
- package/dist/v8/cli/check/messages.js.map +1 -0
- package/dist/v8/cli/content.d.ts +60 -0
- package/dist/v8/cli/content.d.ts.map +1 -0
- package/dist/v8/cli/content.js +231 -0
- package/dist/v8/cli/content.js.map +1 -0
- package/dist/v8/cli/index.d.ts +18 -0
- package/dist/v8/cli/index.d.ts.map +1 -0
- package/dist/v8/cli/index.js +18 -0
- package/dist/v8/cli/index.js.map +1 -0
- package/dist/v8/cli/log.d.ts +9 -0
- package/dist/v8/cli/log.d.ts.map +1 -0
- package/dist/v8/cli/log.js +11 -0
- package/dist/v8/cli/log.js.map +1 -0
- package/dist/v8/cli/main.d.ts +2 -0
- package/dist/v8/cli/main.d.ts.map +1 -0
- package/dist/v8/cli/main.js +9 -0
- package/dist/v8/cli/main.js.map +1 -0
- package/dist/v8/cli/root.d.ts +28 -0
- package/dist/v8/cli/root.d.ts.map +1 -0
- package/dist/v8/cli/root.js +64 -0
- package/dist/v8/cli/root.js.map +1 -0
- package/dist/v8/cli/run.d.ts +13 -0
- package/dist/v8/cli/run.d.ts.map +1 -0
- package/dist/v8/cli/run.js +210 -0
- package/dist/v8/cli/run.js.map +1 -0
- package/dist/v8/cli/schema/builtinSchemas.d.ts +22 -0
- package/dist/v8/cli/schema/builtinSchemas.d.ts.map +1 -0
- package/dist/v8/cli/schema/builtinSchemas.js +213 -0
- package/dist/v8/cli/schema/builtinSchemas.js.map +1 -0
- package/dist/v8/cli/schema/generate.d.ts +50 -0
- package/dist/v8/cli/schema/generate.d.ts.map +1 -0
- package/dist/v8/cli/schema/generate.js +415 -0
- package/dist/v8/cli/schema/generate.js.map +1 -0
- package/dist/v8/cli/schema/index.d.ts +21 -0
- package/dist/v8/cli/schema/index.d.ts.map +1 -0
- package/dist/v8/cli/schema/index.js +51 -0
- package/dist/v8/cli/schema/index.js.map +1 -0
- package/dist/v8/cli/schema/tsProgram.d.ts +126 -0
- package/dist/v8/cli/schema/tsProgram.d.ts.map +1 -0
- package/dist/v8/cli/schema/tsProgram.js +435 -0
- package/dist/v8/cli/schema/tsProgram.js.map +1 -0
- package/dist/v8/cli/schema/typeToSchema.d.ts +94 -0
- package/dist/v8/cli/schema/typeToSchema.d.ts.map +1 -0
- package/dist/v8/cli/schema/typeToSchema.js +752 -0
- package/dist/v8/cli/schema/typeToSchema.js.map +1 -0
- package/dist/v8/cli/serve/server.d.ts +31 -0
- package/dist/v8/cli/serve/server.d.ts.map +1 -0
- package/dist/v8/cli/serve/server.js +247 -0
- package/dist/v8/cli/serve/server.js.map +1 -0
- package/dist/v8/cli/watch.d.ts +20 -0
- package/dist/v8/cli/watch.d.ts.map +1 -0
- package/dist/v8/cli/watch.js +79 -0
- package/dist/v8/cli/watch.js.map +1 -0
- package/dist/v8/client.d.ts +20 -0
- package/dist/v8/client.d.ts.map +1 -0
- package/dist/v8/client.js +115 -0
- package/dist/v8/client.js.map +1 -0
- package/dist/v8/cms.d.ts +9 -0
- package/dist/v8/cms.d.ts.map +1 -0
- package/dist/v8/cms.js +217 -0
- package/dist/v8/cms.js.map +1 -0
- package/dist/v8/content.d.ts +51 -0
- package/dist/v8/content.d.ts.map +1 -0
- package/dist/v8/content.js +218 -0
- package/dist/v8/content.js.map +1 -0
- package/dist/v8/draft.d.ts +48 -0
- package/dist/v8/draft.d.ts.map +1 -0
- package/dist/v8/draft.js +195 -0
- package/dist/v8/draft.js.map +1 -0
- package/dist/v8/errors.d.ts +21 -0
- package/dist/v8/errors.d.ts.map +1 -0
- package/dist/v8/errors.js +39 -0
- package/dist/v8/errors.js.map +1 -0
- package/dist/v8/fetch.d.ts +26 -0
- package/dist/v8/fetch.d.ts.map +1 -0
- package/dist/v8/fetch.js +98 -0
- package/dist/v8/fetch.js.map +1 -0
- package/dist/v8/identity.d.ts +19 -0
- package/dist/v8/identity.d.ts.map +1 -0
- package/dist/v8/identity.js +54 -0
- package/dist/v8/identity.js.map +1 -0
- package/dist/v8/index.d.ts +11 -0
- package/dist/v8/index.d.ts.map +1 -0
- package/dist/v8/index.js +10 -0
- package/dist/v8/index.js.map +1 -0
- package/dist/v8/json.d.ts +19 -0
- package/dist/v8/json.d.ts.map +1 -0
- package/dist/v8/json.js +65 -0
- package/dist/v8/json.js.map +1 -0
- package/dist/v8/matchRoute.d.ts +30 -0
- package/dist/v8/matchRoute.d.ts.map +1 -0
- package/dist/v8/matchRoute.js +175 -0
- package/dist/v8/matchRoute.js.map +1 -0
- package/dist/v8/remoteLoader.d.ts +16 -0
- package/dist/v8/remoteLoader.d.ts.map +1 -0
- package/dist/v8/remoteLoader.js +427 -0
- package/dist/v8/remoteLoader.js.map +1 -0
- package/dist/v8/resolver.d.ts +34 -0
- package/dist/v8/resolver.d.ts.map +1 -0
- package/dist/v8/resolver.js +219 -0
- package/dist/v8/resolver.js.map +1 -0
- package/dist/v8/secrets.d.ts +9 -0
- package/dist/v8/secrets.d.ts.map +1 -0
- package/dist/v8/secrets.js +14 -0
- package/dist/v8/secrets.js.map +1 -0
- package/dist/v8/telemetry.d.ts +61 -0
- package/dist/v8/telemetry.d.ts.map +1 -0
- package/dist/v8/telemetry.js +460 -0
- package/dist/v8/telemetry.js.map +1 -0
- package/dist/v8/types.d.ts +226 -0
- package/dist/v8/types.d.ts.map +1 -0
- package/dist/v8/types.js +2 -0
- package/dist/v8/types.js.map +1 -0
- package/dist/v8/variants.d.ts +3 -0
- package/dist/v8/variants.d.ts.map +1 -0
- package/dist/v8/variants.js +65 -0
- package/dist/v8/variants.js.map +1 -0
- package/package.json +64 -18
- package/src/index.ts +1 -1
- package/src/protocol/canonical.ts +1 -1
- package/src/protocol/ciphertext.ts +1 -1
- package/src/protocol/client.ts +2 -2
- package/src/protocol/conformance/cases/assets.ts +3 -3
- package/src/protocol/conformance/cases/guards.ts +4 -4
- package/src/protocol/conformance/cases/reads.ts +4 -4
- package/src/protocol/conformance/cases/types.ts +1 -1
- package/src/protocol/conformance/cases/wire.ts +4 -4
- package/src/protocol/conformance/cases/writes.ts +4 -4
- package/src/protocol/conformance/contentHashFixtures.ts +57 -0
- package/src/protocol/conformance/context.ts +4 -4
- package/src/protocol/conformance/index.ts +15 -10
- package/src/protocol/index.ts +14 -7
- package/src/protocol/params.ts +2 -2
- package/src/protocol/secrets.ts +3 -3
- package/src/protocol/server/assets.ts +6 -6
- package/src/protocol/server/auth.ts +1 -1
- package/src/protocol/server/content.ts +5 -5
- package/src/protocol/server/core.ts +12 -6
- package/src/protocol/server/handler.ts +6 -6
- package/src/protocol/server/http.ts +1 -1
- package/src/protocol/server/index.ts +3 -3
- package/src/protocol/server/methods/apply.ts +9 -9
- package/src/protocol/server/methods/read.ts +5 -5
- package/src/protocol/server/rpc.ts +6 -6
- package/src/protocol/storage/fs/index.ts +7 -7
- package/src/protocol/storage/fs/lock.ts +1 -1
- package/src/protocol/storage/fs/unsupported.ts +2 -2
- package/src/protocol/storage/memory.ts +4 -4
- package/src/protocol/storage.ts +1 -1
- package/src/v8/analytics.ts +2 -2
- package/src/v8/builtins/data.ts +1 -1
- package/src/v8/builtins/index.ts +6 -6
- package/src/v8/builtins/lazy.ts +1 -1
- package/src/v8/builtins/legacy.ts +1 -1
- package/src/v8/builtins/multivariate.ts +1 -1
- package/src/v8/builtins/secret.ts +2 -2
- package/src/v8/canonical.ts +36 -0
- package/src/v8/cli/builtins.ts +2 -2
- package/src/v8/cli/check/index.ts +11 -11
- package/src/v8/cli/content.ts +6 -6
- package/src/v8/cli/index.ts +7 -7
- package/src/v8/cli/main.ts +1 -1
- package/src/v8/cli/run.ts +7 -7
- package/src/v8/cli/schema/builtinSchemas.ts +1 -1
- package/src/v8/cli/schema/generate.ts +8 -7
- package/src/v8/cli/schema/index.ts +4 -4
- package/src/v8/cli/schema/tsProgram.ts +18 -1
- package/src/v8/cli/schema/typeToSchema.ts +100 -4
- package/src/v8/cli/serve/server.ts +9 -9
- package/src/v8/client.ts +5 -5
- package/src/v8/cms.ts +23 -11
- package/src/v8/content.ts +58 -22
- package/src/v8/draft.ts +75 -6
- package/src/v8/errors.ts +1 -1
- package/src/v8/fetch.ts +1 -1
- package/src/v8/identity.ts +1 -1
- package/src/v8/index.ts +5 -5
- package/src/v8/matchRoute.ts +1 -1
- package/src/v8/remoteLoader.ts +246 -26
- package/src/v8/resolver.ts +6 -6
- package/src/v8/secrets.ts +1 -1
- package/src/v8/telemetry.ts +5 -5
- package/src/v8/types.ts +14 -1
- package/src/v8/variants.ts +61 -0
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* in api-reference › Types). They're always in the schema, unless the block
|
|
4
4
|
* map declares the same key, which replaces the built-in.
|
|
5
5
|
*/
|
|
6
|
-
import { lazySchema, resolvableRef, sectionRef } from "./typeToSchema";
|
|
6
|
+
import { lazySchema, resolvableRef, sectionRef } from "./typeToSchema.ts";
|
|
7
7
|
|
|
8
8
|
export type ManifestGroup = "sections" | "matchers" | "loaders" | "pages" | "redirects" | "content";
|
|
9
9
|
|
|
@@ -12,21 +12,22 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import fs from "node:fs";
|
|
14
14
|
import path from "node:path";
|
|
15
|
-
import { SCHEMA_FORMAT } from "../../../protocol/types";
|
|
16
|
-
import { BUILT_IN_BLOCKS, LEGACY_ALIASES } from "../builtins";
|
|
17
|
-
import { CliError, type DecoPaths, packageVersion } from "../root";
|
|
15
|
+
import { SCHEMA_FORMAT } from "../../../protocol/types.ts";
|
|
16
|
+
import { BUILT_IN_BLOCKS, LEGACY_ALIASES } from "../builtins.ts";
|
|
17
|
+
import { CliError, type DecoPaths, packageVersion } from "../root.ts";
|
|
18
18
|
import {
|
|
19
19
|
BUILT_IN_GROUPS,
|
|
20
20
|
builtInDefinition,
|
|
21
21
|
flatDefinition,
|
|
22
22
|
legacyMultivariateValue,
|
|
23
23
|
type ManifestGroup,
|
|
24
|
-
} from "./builtinSchemas";
|
|
25
|
-
import { createTsProject, type TsNode as Node, type TsType as Type } from "./tsProgram";
|
|
24
|
+
} from "./builtinSchemas.ts";
|
|
25
|
+
import { createTsProject, type TsNode as Node, type TsType as Type } from "./tsProgram.ts";
|
|
26
26
|
import {
|
|
27
27
|
awaitedOf,
|
|
28
28
|
getJsDocTags,
|
|
29
29
|
isDescriptorType,
|
|
30
|
+
isFreeFormMap,
|
|
30
31
|
isJsxType,
|
|
31
32
|
nonNullable,
|
|
32
33
|
RESOLVABLE_KEY,
|
|
@@ -35,7 +36,7 @@ import {
|
|
|
35
36
|
stableFileId,
|
|
36
37
|
toBase64,
|
|
37
38
|
typeToJsonSchema,
|
|
38
|
-
} from "./typeToSchema";
|
|
39
|
+
} from "./typeToSchema.ts";
|
|
39
40
|
|
|
40
41
|
const MANIFEST_GROUPS: ManifestGroup[] = [
|
|
41
42
|
"sections",
|
|
@@ -283,7 +284,7 @@ export async function generateSchema(paths: DecoPaths): Promise<SchemaResult> {
|
|
|
283
284
|
root,
|
|
284
285
|
fitting(type) {
|
|
285
286
|
const target = nonNullable(type);
|
|
286
|
-
if (target.isAny() || target.isUnknown()) return [];
|
|
287
|
+
if (target.isAny() || target.isUnknown() || isFreeFormMap(target)) return [];
|
|
287
288
|
const cached = fitCache.get(target.compilerType);
|
|
288
289
|
if (cached) return cached;
|
|
289
290
|
const keys = candidates
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
import { writeIfChanged } from "../content";
|
|
3
|
-
import { consoleReporter, type Reporter } from "../log";
|
|
4
|
-
import { CliError, type DecoPaths, decoPaths, findDecoRoot } from "../root";
|
|
5
|
-
import { generateSchema, type SchemaResult } from "./generate";
|
|
2
|
+
import { writeIfChanged } from "../content.ts";
|
|
3
|
+
import { consoleReporter, type Reporter } from "../log.ts";
|
|
4
|
+
import { CliError, type DecoPaths, decoPaths, findDecoRoot } from "../root.ts";
|
|
5
|
+
import { generateSchema, type SchemaResult } from "./generate.ts";
|
|
6
6
|
|
|
7
7
|
export interface SchemaOptions {
|
|
8
8
|
root?: string;
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
import fs from "node:fs";
|
|
18
18
|
import path from "node:path";
|
|
19
19
|
import type * as TS from "typescript";
|
|
20
|
-
import { CliError } from "../root";
|
|
20
|
+
import { CliError } from "../root.ts";
|
|
21
21
|
|
|
22
22
|
type TypeScript = typeof TS;
|
|
23
23
|
|
|
@@ -321,6 +321,23 @@ export class TsNode {
|
|
|
321
321
|
return t && typeof t === "object" && "kind" in t ? this.ctx.node(t) : undefined;
|
|
322
322
|
}
|
|
323
323
|
|
|
324
|
+
/**
|
|
325
|
+
* The declarations of the type aliases a type annotation names, as written:
|
|
326
|
+
* `Kind` and `Kind | null` both give `Kind`'s. The checker drops the alias
|
|
327
|
+
* from `Kind | undefined`, so this is how a field finds its alias.
|
|
328
|
+
*/
|
|
329
|
+
getAliasDeclarationTexts(): string[] {
|
|
330
|
+
const ts = this.ctx.ts;
|
|
331
|
+
const node = this.compilerNode as TS.TypeNode;
|
|
332
|
+
const members = ts.isUnionTypeNode(node) ? node.types : [node];
|
|
333
|
+
const texts: string[] = [];
|
|
334
|
+
for (const member of members) {
|
|
335
|
+
const decl = this.ctx.checker.getTypeFromTypeNode(member).aliasSymbol?.declarations?.[0];
|
|
336
|
+
if (decl) texts.push(decl.getText(decl.getSourceFile()));
|
|
337
|
+
}
|
|
338
|
+
return texts;
|
|
339
|
+
}
|
|
340
|
+
|
|
324
341
|
/** Whether `other` is this node or inside it. */
|
|
325
342
|
contains(other: TsNode): boolean {
|
|
326
343
|
const a = this.compilerNode;
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
|
|
24
24
|
import fs from "node:fs";
|
|
25
25
|
import path from "node:path";
|
|
26
|
-
import type { TsSymbol as MorphSymbol, TsType as Type } from "./tsProgram";
|
|
26
|
+
import type { TsSymbol as MorphSymbol, TsType as Type } from "./tsProgram.ts";
|
|
27
27
|
|
|
28
28
|
export const RESOLVABLE_KEY = "Resolvable";
|
|
29
29
|
export const SECTION_REF_KEY = "__SECTION_REF__";
|
|
@@ -123,9 +123,20 @@ function parseOptions(raw: string): { values: (string | number)[]; labels?: stri
|
|
|
123
123
|
return labelled ? { values, labels } : { values };
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
+
/**
|
|
127
|
+
* `@format` spellings that name a standard format under another name, kept
|
|
128
|
+
* from v7: `@format datetime` (Eitri's vocabulary) is the `date-time` picker,
|
|
129
|
+
* and `deco check` validates it as one.
|
|
130
|
+
*/
|
|
131
|
+
const FORMAT_ALIASES: Record<string, string> = { datetime: "date-time" };
|
|
132
|
+
|
|
126
133
|
function applyJsDocToSchema(schema: any, tags: Record<string, string>): void {
|
|
127
134
|
for (const [tag, value] of Object.entries(tags)) {
|
|
128
135
|
if (tag === "ignore") continue;
|
|
136
|
+
if (tag === "format") {
|
|
137
|
+
schema.format = FORMAT_ALIASES[value] ?? value;
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
129
140
|
if (tag === "hide") {
|
|
130
141
|
schema.hide = "true";
|
|
131
142
|
continue;
|
|
@@ -324,6 +335,19 @@ export function nonNullable(type: Type): Type {
|
|
|
324
335
|
return parts.length === 1 ? parts[0] : type.getNonNullableType();
|
|
325
336
|
}
|
|
326
337
|
|
|
338
|
+
/**
|
|
339
|
+
* `Record<string, any>` and friends: a map of anything, which every block's
|
|
340
|
+
* output fits. It's a free-form value, not a place for a block, so the field
|
|
341
|
+
* doesn't offer the saved-block picker or list every block as a choice.
|
|
342
|
+
*/
|
|
343
|
+
export function isFreeFormMap(type: Type): boolean {
|
|
344
|
+
const t = nonNullable(type);
|
|
345
|
+
if (!t.isObject() || t.getProperties().length > 0 || t.getCallSignatures().length > 0)
|
|
346
|
+
return false;
|
|
347
|
+
const value = t.getStringIndexType() ?? t.getNumberIndexType();
|
|
348
|
+
return value !== undefined && (value.isAny() || value.isUnknown());
|
|
349
|
+
}
|
|
350
|
+
|
|
327
351
|
/** Types a block can fill: objects, arrays and intersections of objects, not primitives. */
|
|
328
352
|
function isObjectLike(type: Type): boolean {
|
|
329
353
|
const t = nonNullable(type);
|
|
@@ -434,10 +458,51 @@ function fieldSchema(
|
|
|
434
458
|
}
|
|
435
459
|
|
|
436
460
|
const schema = typeToJsonSchema(propType, new Set(visited), ctx);
|
|
461
|
+
orderEnumByHint(schema, typeHint);
|
|
437
462
|
applyWidgetFormat(schema, typeHint);
|
|
438
463
|
return schema;
|
|
439
464
|
}
|
|
440
465
|
|
|
466
|
+
/**
|
|
467
|
+
* Literal values in the order `text` (the declaration as written) spells them.
|
|
468
|
+
* The checker orders a union's members by when it first met each literal,
|
|
469
|
+
* which another file can change, so `"a" | "b"` could come out as `["b", "a"]`.
|
|
470
|
+
* Values `text` doesn't spell all of keep the checker's order.
|
|
471
|
+
*/
|
|
472
|
+
export function inDeclaredOrder<T extends string | number>(values: T[], text: string): T[] {
|
|
473
|
+
const at = values.map((value) => {
|
|
474
|
+
const spelled =
|
|
475
|
+
typeof value === "string"
|
|
476
|
+
? [`"${value}"`, `'${value}'`, `\`${value}\``]
|
|
477
|
+
.map((q) => text.indexOf(q))
|
|
478
|
+
.filter((i) => i >= 0)
|
|
479
|
+
: [
|
|
480
|
+
...text.matchAll(
|
|
481
|
+
new RegExp(`(?<![\\w.])${String(value).replace(".", "\\.")}(?![\\w.])`, "g"),
|
|
482
|
+
),
|
|
483
|
+
].map((m) => m.index ?? -1);
|
|
484
|
+
return spelled.length > 0 ? Math.min(...spelled) : -1;
|
|
485
|
+
});
|
|
486
|
+
if (at.some((i) => i < 0)) return values;
|
|
487
|
+
return values
|
|
488
|
+
.map((value, i) => ({ value, at: at[i] }))
|
|
489
|
+
.sort((a, b) => a.at - b.at)
|
|
490
|
+
.map((e) => e.value);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/** Reorder a literal select (or a list of them) by the field's annotation. */
|
|
494
|
+
function orderEnumByHint(schema: any, typeHint: string): void {
|
|
495
|
+
if (Array.isArray(schema?.enum)) schema.enum = inDeclaredOrder(schema.enum, typeHint);
|
|
496
|
+
else if (Array.isArray(schema?.items?.enum)) {
|
|
497
|
+
schema.items.enum = inDeclaredOrder(schema.items.enum, typeHint);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/** The declaration text of a type alias, for ordering its literal members. */
|
|
502
|
+
function aliasDeclarationText(type: Type): string {
|
|
503
|
+
return type.getAliasSymbol()?.getDeclarations()[0]?.getText() ?? "";
|
|
504
|
+
}
|
|
505
|
+
|
|
441
506
|
/** The "plain value" branch of a field that blocks can fill. */
|
|
442
507
|
function inlineSchema(type: Type, ctx: SchemaContext, visited: Set<string>): any {
|
|
443
508
|
if (type.isArray()) {
|
|
@@ -514,12 +579,20 @@ export function typeToJsonSchema(
|
|
|
514
579
|
}
|
|
515
580
|
// String-literal unions and string enums: a select, written into the schema.
|
|
516
581
|
if (nonNull.every((t) => t.isStringLiteral())) {
|
|
517
|
-
const
|
|
582
|
+
const values = nonNull.map((t) => t.getLiteralValue() as string);
|
|
583
|
+
const result: any = {
|
|
584
|
+
type: "string",
|
|
585
|
+
enum: inDeclaredOrder(values, aliasDeclarationText(type)),
|
|
586
|
+
};
|
|
518
587
|
if (isNullable) result.nullable = true;
|
|
519
588
|
return result;
|
|
520
589
|
}
|
|
521
590
|
if (nonNull.every((t) => t.isNumberLiteral())) {
|
|
522
|
-
const
|
|
591
|
+
const values = nonNull.map((t) => t.getLiteralValue() as number);
|
|
592
|
+
const result: any = {
|
|
593
|
+
type: "number",
|
|
594
|
+
enum: inDeclaredOrder(values, aliasDeclarationText(type)),
|
|
595
|
+
};
|
|
523
596
|
if (isNullable) result.nullable = true;
|
|
524
597
|
return result;
|
|
525
598
|
}
|
|
@@ -630,6 +703,7 @@ export function typeToJsonSchema(
|
|
|
630
703
|
}
|
|
631
704
|
|
|
632
705
|
const schema = fieldSchema(propType, typeHint, ctx, visited);
|
|
706
|
+
if (typeNode) orderEnumByHint(schema, typeNode.getAliasDeclarationTexts().join("\n"));
|
|
633
707
|
if (schema.anyOf && schema.anyOf[0]?.$ref === resolvableRef().$ref) {
|
|
634
708
|
// A block-ref field: nullability lives on the wrapper.
|
|
635
709
|
if (isNullableHint(optional, typeHint)) schema.nullable = true;
|
|
@@ -662,9 +736,14 @@ export function typeToJsonSchema(
|
|
|
662
736
|
* A machine-independent id for a source file: relative to the app root, or
|
|
663
737
|
* `<package name>/<path in package>` for a file in a dependency (including a
|
|
664
738
|
* workspace package the checker reached through a symlink).
|
|
739
|
+
*
|
|
740
|
+
* A declaration file with a declaration map (`x.d.ts` + `x.d.ts.map`, as
|
|
741
|
+
* `tsc` emits into a package's dist/) is named after the source it was
|
|
742
|
+
* compiled from, so a type keeps one id whether the checker read the
|
|
743
|
+
* package's compiled `.d.ts` or its `.ts` source (the "source" condition).
|
|
665
744
|
*/
|
|
666
745
|
export function stableFileId(filePath: string, root: string): string {
|
|
667
|
-
const file = filePath.replace(/^file:\/+/, "/");
|
|
746
|
+
const file = sourceOfDeclaration(filePath.replace(/^file:\/+/, "/"));
|
|
668
747
|
const nm = file.lastIndexOf("/node_modules/");
|
|
669
748
|
if (nm >= 0) return file.slice(nm + "/node_modules/".length);
|
|
670
749
|
const rel = path.relative(root, file).split(path.sep).join("/");
|
|
@@ -687,3 +766,20 @@ export function stableFileId(filePath: string, root: string): string {
|
|
|
687
766
|
dir = parent;
|
|
688
767
|
}
|
|
689
768
|
}
|
|
769
|
+
|
|
770
|
+
/** The `.ts` file a `.d.ts` was emitted from, per its declaration map; else the file itself. */
|
|
771
|
+
function sourceOfDeclaration(file: string): string {
|
|
772
|
+
if (!/\.d\.[cm]?ts$/.test(file)) return file;
|
|
773
|
+
try {
|
|
774
|
+
const map = JSON.parse(fs.readFileSync(`${file}.map`, "utf8")) as {
|
|
775
|
+
sources?: unknown;
|
|
776
|
+
sourceRoot?: unknown;
|
|
777
|
+
};
|
|
778
|
+
const source = Array.isArray(map.sources) ? map.sources[0] : undefined;
|
|
779
|
+
if (typeof source !== "string") return file;
|
|
780
|
+
const sourceRoot = typeof map.sourceRoot === "string" ? map.sourceRoot : "";
|
|
781
|
+
return path.resolve(path.dirname(file), sourceRoot, source);
|
|
782
|
+
} catch {
|
|
783
|
+
return file;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
@@ -20,15 +20,15 @@ import http from "node:http";
|
|
|
20
20
|
import type { AddressInfo } from "node:net";
|
|
21
21
|
import path from "node:path";
|
|
22
22
|
import { Readable } from "node:stream";
|
|
23
|
-
import { ErrorCode } from "../../../protocol/errors";
|
|
24
|
-
import { blockNameFromFile } from "../../../protocol/keys";
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import
|
|
28
|
-
import {
|
|
29
|
-
import { readSavedBlocks, writeContent } from "../content";
|
|
30
|
-
import { consoleReporter, type Reporter } from "../log";
|
|
31
|
-
import { CliError, decoPaths, findDecoRoot, packageVersion } from "../root";
|
|
23
|
+
import { ErrorCode } from "../../../protocol/errors.ts";
|
|
24
|
+
import { blockNameFromFile } from "../../../protocol/keys.ts";
|
|
25
|
+
import { createAssetHandler } from "../../../protocol/server/assets.ts";
|
|
26
|
+
import { createContentHandler } from "../../../protocol/server/index.ts";
|
|
27
|
+
import { createFsStorage } from "../../../protocol/storage/fs/index.ts";
|
|
28
|
+
import type { ContentStorage } from "../../../protocol/storage.ts";
|
|
29
|
+
import { readSavedBlocks, writeContent } from "../content.ts";
|
|
30
|
+
import { consoleReporter, type Reporter } from "../log.ts";
|
|
31
|
+
import { CliError, decoPaths, findDecoRoot, packageVersion } from "../root.ts";
|
|
32
32
|
|
|
33
33
|
/** The site editor's origins: the browser origins allowed by default. */
|
|
34
34
|
const STUDIO_ORIGINS = [
|
package/src/v8/client.ts
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* A client: one revision, loaded on first use and read for the rest of its
|
|
3
3
|
* life, plus a memo of block results. Create one per request.
|
|
4
4
|
*/
|
|
5
|
-
import { errors, isResolutionError, ResolutionError } from "./errors";
|
|
6
|
-
import { isBlock } from "./json";
|
|
7
|
-
import { Resolver } from "./resolver";
|
|
8
|
-
import type { ClientTelemetry } from "./telemetry";
|
|
5
|
+
import { errors, isResolutionError, ResolutionError } from "./errors.ts";
|
|
6
|
+
import { isBlock } from "./json.ts";
|
|
7
|
+
import { Resolver } from "./resolver.ts";
|
|
8
|
+
import type { ClientTelemetry } from "./telemetry.ts";
|
|
9
9
|
import type {
|
|
10
10
|
Block,
|
|
11
11
|
Blocks,
|
|
@@ -15,7 +15,7 @@ import type {
|
|
|
15
15
|
ResolveOptions,
|
|
16
16
|
Result,
|
|
17
17
|
Snapshot,
|
|
18
|
-
} from "./types";
|
|
18
|
+
} from "./types.ts";
|
|
19
19
|
|
|
20
20
|
interface ClientOptions {
|
|
21
21
|
/** Loads this client's snapshot; called at most once. */
|
package/src/v8/cms.ts
CHANGED
|
@@ -6,15 +6,17 @@
|
|
|
6
6
|
* a package loaded twice (two bundles, a dev reload) still shares one content
|
|
7
7
|
* cache. See /next/api-reference#one-instance-per-process.
|
|
8
8
|
*/
|
|
9
|
-
import { runInBackground } from "./background";
|
|
10
|
-
import { builtIns } from "./builtins/index";
|
|
11
|
-
import { secretBlock } from "./builtins/secret";
|
|
12
|
-
import { CMSClient } from "./client";
|
|
13
|
-
import { ContentStore, isLoader, isSnapshot } from "./content";
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import
|
|
9
|
+
import { runInBackground } from "./background.ts";
|
|
10
|
+
import { builtIns } from "./builtins/index.ts";
|
|
11
|
+
import { secretBlock } from "./builtins/secret.ts";
|
|
12
|
+
import { CMSClient } from "./client.ts";
|
|
13
|
+
import { ContentStore, isLoader, isSnapshot } from "./content.ts";
|
|
14
|
+
import { parseDraftPointer } from "./draft.ts";
|
|
15
|
+
import { clearGlobals, contentIdentity, fnv1a, readEnv } from "./identity.ts";
|
|
16
|
+
import { remoteLoader, resetRemoteLoaders } from "./remoteLoader.ts";
|
|
17
|
+
import { resolveDestination, setCurrentTelemetry, TelemetryPipeline } from "./telemetry.ts";
|
|
18
|
+
import type { Blocks, Client, CMS, CMSConfig, Loader, Snapshot } from "./types.ts";
|
|
19
|
+
import { forceVariants } from "./variants.ts";
|
|
18
20
|
|
|
19
21
|
const INSTANCE_PREFIX = "decocms.blocks.cms:";
|
|
20
22
|
const MIN_INTERVAL = 60_000;
|
|
@@ -39,7 +41,7 @@ class CMSInstance implements CMS {
|
|
|
39
41
|
readonly #telemetry: TelemetryPipeline | undefined;
|
|
40
42
|
#blocks: Blocks;
|
|
41
43
|
/**
|
|
42
|
-
* When the next check is due. The first is on the first `forRelease()`, not
|
|
44
|
+
* When the next check is due. The first is on the first `forRelease()` or `forDraft()`, not
|
|
43
45
|
* at construction: Workers read `Date.now()` as 0 at module scope.
|
|
44
46
|
*/
|
|
45
47
|
#nextCheck: number | undefined;
|
|
@@ -73,8 +75,18 @@ class CMSInstance implements CMS {
|
|
|
73
75
|
);
|
|
74
76
|
}
|
|
75
77
|
|
|
78
|
+
/**
|
|
79
|
+
* The draft, with the variants the pointer forces (even over a source with no
|
|
80
|
+
* drafts). A draft inherits local production, so it schedules the same
|
|
81
|
+
* background release check `forRelease()` does (never in front of the draft).
|
|
82
|
+
*/
|
|
76
83
|
forDraft(pointer: string): Client {
|
|
77
|
-
|
|
84
|
+
this.#scheduleUpdate();
|
|
85
|
+
const variants = parseDraftPointer(pointer)?.variants;
|
|
86
|
+
if (variants === undefined) return this.#client(() => this.#store.draft(pointer));
|
|
87
|
+
return this.#client(() =>
|
|
88
|
+
this.#store.draft(pointer).then((snapshot) => forceVariants(snapshot, variants)),
|
|
89
|
+
);
|
|
78
90
|
}
|
|
79
91
|
|
|
80
92
|
forRevision(revision: string): Client {
|
package/src/v8/content.ts
CHANGED
|
@@ -7,13 +7,19 @@
|
|
|
7
7
|
* revision string a client may hand back, so it must only ever reach published
|
|
8
8
|
* content, never a draft someone loaded with a pointer.
|
|
9
9
|
*/
|
|
10
|
-
import { formatDraftPointer, parseDraftPointer } from "./draft";
|
|
11
|
-
import { errors, isResolutionError } from "./errors";
|
|
12
|
-
import { isPlainObject } from "./json";
|
|
13
|
-
import type { Loader, Snapshot } from "./types";
|
|
10
|
+
import { formatDraftPointer, parseDraftPointer } from "./draft.ts";
|
|
11
|
+
import { errors, isResolutionError } from "./errors.ts";
|
|
12
|
+
import { isPlainObject } from "./json.ts";
|
|
13
|
+
import type { Loader, Snapshot } from "./types.ts";
|
|
14
14
|
|
|
15
15
|
const SERVED_REVISIONS = 16;
|
|
16
|
-
|
|
16
|
+
/** Composed drafts kept per CMS (see /next/studio-implementation's initial limits). */
|
|
17
|
+
const CACHED_DRAFTS = 3;
|
|
18
|
+
/**
|
|
19
|
+
* How long a loaded draft is reused before `load(pointer)` runs again, so a
|
|
20
|
+
* loader's own checks (a hosted grant's expiry) apply on a warm server too.
|
|
21
|
+
*/
|
|
22
|
+
const DRAFT_TTL_MS = 60_000;
|
|
17
23
|
|
|
18
24
|
export function isLoader(content: unknown): content is Loader {
|
|
19
25
|
return (
|
|
@@ -36,7 +42,9 @@ export class ContentStore {
|
|
|
36
42
|
#source: Snapshot | Loader;
|
|
37
43
|
#release: Promise<Snapshot> | undefined;
|
|
38
44
|
#updating: Promise<{ updated: boolean }> | undefined;
|
|
39
|
-
readonly #drafts = new BoundedMap<string, Promise<Snapshot
|
|
45
|
+
readonly #drafts = new BoundedMap<string, { pending: Promise<Snapshot>; at: number }>(
|
|
46
|
+
CACHED_DRAFTS,
|
|
47
|
+
);
|
|
40
48
|
readonly #served = new BoundedMap<string, Snapshot>(SERVED_REVISIONS);
|
|
41
49
|
|
|
42
50
|
constructor(source: Snapshot | Loader) {
|
|
@@ -70,8 +78,10 @@ export class ContentStore {
|
|
|
70
78
|
|
|
71
79
|
/**
|
|
72
80
|
* The draft a pointer names. A snapshot has no drafts and ignores the
|
|
73
|
-
* pointer. A loader gets `load(pointer)` only for a pointer that parses
|
|
74
|
-
*
|
|
81
|
+
* pointer. A loader gets `load(pointer)` only for a pointer that parses,
|
|
82
|
+
* formatted again without its `__variant` parameters (so every variant of
|
|
83
|
+
* one draft shares one load); anything else is `LOADER_FAILED`, never a
|
|
84
|
+
* silent fallback to the release. A loaded draft is reused for a minute.
|
|
75
85
|
*/
|
|
76
86
|
draft(pointer: string): Promise<Snapshot> {
|
|
77
87
|
const source = this.#source;
|
|
@@ -80,13 +90,20 @@ export class ContentStore {
|
|
|
80
90
|
if (parsed === null) {
|
|
81
91
|
return Promise.reject(errors.loaderFailed(`invalid draft pointer "${truncate(pointer)}"`));
|
|
82
92
|
}
|
|
83
|
-
|
|
93
|
+
// The draft itself, without the variants a preview forces: those apply per client.
|
|
94
|
+
const key = formatDraftPointer({
|
|
95
|
+
host: parsed.host,
|
|
96
|
+
path: parsed.path,
|
|
97
|
+
version: parsed.version,
|
|
98
|
+
});
|
|
84
99
|
const cached = this.#drafts.get(key);
|
|
85
|
-
if (cached !== undefined) return cached;
|
|
86
|
-
const
|
|
87
|
-
this.#drafts.set(key,
|
|
88
|
-
pending.catch(() =>
|
|
89
|
-
|
|
100
|
+
if (cached !== undefined && Date.now() - cached.at < DRAFT_TTL_MS) return cached.pending;
|
|
101
|
+
const entry = { pending: this.#load(source, key), at: Date.now() };
|
|
102
|
+
this.#drafts.set(key, entry);
|
|
103
|
+
entry.pending.catch(() => {
|
|
104
|
+
if (this.#drafts.get(key) === entry) this.#drafts.delete(key);
|
|
105
|
+
});
|
|
106
|
+
return entry.pending;
|
|
90
107
|
}
|
|
91
108
|
|
|
92
109
|
/** A release revision this store has served, or the release when it's unknown (drafts included). */
|
|
@@ -131,7 +148,9 @@ export class ContentStore {
|
|
|
131
148
|
const previous = this.#source;
|
|
132
149
|
if (source === previous) {
|
|
133
150
|
// The same loader (a hosted remoteLoader that adopted new fallback content): re-read it.
|
|
151
|
+
// Cached drafts were layered over the old content, so they go too.
|
|
134
152
|
this.#release = undefined;
|
|
153
|
+
this.#drafts.clear();
|
|
135
154
|
return;
|
|
136
155
|
}
|
|
137
156
|
if (isSnapshot(previous)) this.#served.delete(previous.revision);
|
|
@@ -167,29 +186,46 @@ function truncate(value: string): string {
|
|
|
167
186
|
return value.length > 80 ? `${value.slice(0, 80)}…` : value;
|
|
168
187
|
}
|
|
169
188
|
|
|
170
|
-
/**
|
|
171
|
-
|
|
189
|
+
/**
|
|
190
|
+
* A Map that forgets its least recently used entries past `limit`, counted by
|
|
191
|
+
* `size` (one per entry unless given).
|
|
192
|
+
*/
|
|
193
|
+
export class BoundedMap<K, V> {
|
|
172
194
|
readonly #map = new Map<K, V>();
|
|
173
|
-
|
|
195
|
+
#total = 0;
|
|
196
|
+
constructor(
|
|
197
|
+
readonly limit: number,
|
|
198
|
+
readonly size: (value: V) => number = () => 1,
|
|
199
|
+
) {}
|
|
174
200
|
|
|
175
201
|
get(key: K): V | undefined {
|
|
176
|
-
|
|
202
|
+
const value = this.#map.get(key);
|
|
203
|
+
if (value !== undefined) {
|
|
204
|
+
this.#map.delete(key);
|
|
205
|
+
this.#map.set(key, value);
|
|
206
|
+
}
|
|
207
|
+
return value;
|
|
177
208
|
}
|
|
178
209
|
|
|
179
210
|
set(key: K, value: V): void {
|
|
180
|
-
this
|
|
211
|
+
this.delete(key);
|
|
181
212
|
this.#map.set(key, value);
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
if (
|
|
213
|
+
this.#total += this.size(value);
|
|
214
|
+
for (const [oldest, old] of this.#map) {
|
|
215
|
+
if (this.#total <= this.limit || oldest === key) break;
|
|
216
|
+
this.#map.delete(oldest);
|
|
217
|
+
this.#total -= this.size(old);
|
|
185
218
|
}
|
|
186
219
|
}
|
|
187
220
|
|
|
188
221
|
delete(key: K): void {
|
|
222
|
+
if (!this.#map.has(key)) return;
|
|
223
|
+
this.#total -= this.size(this.#map.get(key) as V);
|
|
189
224
|
this.#map.delete(key);
|
|
190
225
|
}
|
|
191
226
|
|
|
192
227
|
clear(): void {
|
|
193
228
|
this.#map.clear();
|
|
229
|
+
this.#total = 0;
|
|
194
230
|
}
|
|
195
231
|
}
|
package/src/v8/draft.ts
CHANGED
|
@@ -2,8 +2,12 @@
|
|
|
2
2
|
* Draft pointers (see /next/api-reference#draft-pointers): the string
|
|
3
3
|
* `<host[:port]><path[?query]>@<version>` that names a draft, and the two
|
|
4
4
|
* helpers that carry one from a `?__draft=` link into a cookie.
|
|
5
|
+
*
|
|
6
|
+
* The query's reserved `__variant` parameters are the variants a preview
|
|
7
|
+
* forces (`<block>@<path>=<index>`, URL-encoded, one per multivariate); the
|
|
8
|
+
* parser lifts them out of `path` into `variants`.
|
|
5
9
|
*/
|
|
6
|
-
import type { DraftPointer } from "./types";
|
|
10
|
+
import type { DraftPointer, ForcedVariant } from "./types.ts";
|
|
7
11
|
|
|
8
12
|
/** The draft cookie's name, for frameworks whose cookie API has no Request (Next.js `cookies()`). */
|
|
9
13
|
export const DRAFT_COOKIE = "deco-draft";
|
|
@@ -18,6 +22,8 @@ const VERSION_RE = /^[A-Za-z0-9._-]{1,64}$/;
|
|
|
18
22
|
/** Rooted path with an optional query; no `@`, `#`, whitespace or scheme characters. */
|
|
19
23
|
const PATH_RE = /^\/[A-Za-z0-9/_.%~=&?-]*$/;
|
|
20
24
|
const MAX_POINTER_LENGTH = 4096;
|
|
25
|
+
const VARIANT_PARAM = "__variant=";
|
|
26
|
+
const INDEX_RE = /^(0|[1-9][0-9]{0,3})$/;
|
|
21
27
|
|
|
22
28
|
/**
|
|
23
29
|
* Parses a pointer, strictly: `null` on a scheme, a stray `@`, an unrooted
|
|
@@ -39,7 +45,12 @@ export function parseDraftPointer(raw: string | null | undefined): DraftPointer
|
|
|
39
45
|
if (!PATH_RE.test(path) || path.startsWith("//")) return null;
|
|
40
46
|
|
|
41
47
|
const host = normalizeHost(location.slice(0, slash));
|
|
42
|
-
|
|
48
|
+
if (host === null) return null;
|
|
49
|
+
const split = splitVariants(path);
|
|
50
|
+
if (split === null) return null;
|
|
51
|
+
return split.variants.length === 0
|
|
52
|
+
? { host, path, version }
|
|
53
|
+
: { host, path: split.path, version, variants: split.variants };
|
|
43
54
|
}
|
|
44
55
|
|
|
45
56
|
/**
|
|
@@ -48,12 +59,70 @@ export function parseDraftPointer(raw: string | null | undefined): DraftPointer
|
|
|
48
59
|
* bad pointer is caught where it's built rather than where it's loaded.
|
|
49
60
|
*/
|
|
50
61
|
export function formatDraftPointer(pointer: DraftPointer): string {
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
|
|
62
|
+
const variants = pointer.variants ?? [];
|
|
63
|
+
const params = variants.map((variant) => VARIANT_PARAM + encodeVariant(variant));
|
|
64
|
+
const path =
|
|
65
|
+
params.length === 0
|
|
66
|
+
? pointer.path
|
|
67
|
+
: `${pointer.path}${pointer.path.includes("?") ? "&" : "?"}${params.join("&")}`;
|
|
68
|
+
const parsed = parseDraftPointer(`${pointer.host}${path}@${pointer.version}`);
|
|
69
|
+
if (
|
|
70
|
+
parsed === null ||
|
|
71
|
+
parsed.path !== pointer.path ||
|
|
72
|
+
parsed.version !== pointer.version ||
|
|
73
|
+
JSON.stringify(parsed.variants ?? []) !== JSON.stringify(variants.map(plainVariant))
|
|
74
|
+
) {
|
|
54
75
|
throw new TypeError(`invalid draft pointer parts: ${JSON.stringify(pointer)}`);
|
|
55
76
|
}
|
|
56
|
-
return `${parsed.host}${
|
|
77
|
+
return `${parsed.host}${path}@${parsed.version}`;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** The path without its `__variant` parameters, and the variants they force; `null` on a bad one. */
|
|
81
|
+
function splitVariants(path: string): { path: string; variants: ForcedVariant[] } | null {
|
|
82
|
+
const q = path.indexOf("?");
|
|
83
|
+
if (q === -1) return { path, variants: [] };
|
|
84
|
+
const kept: string[] = [];
|
|
85
|
+
const variants: ForcedVariant[] = [];
|
|
86
|
+
for (const param of path.slice(q + 1).split("&")) {
|
|
87
|
+
if (!param.startsWith(VARIANT_PARAM)) {
|
|
88
|
+
kept.push(param);
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const variant = decodeVariant(param.slice(VARIANT_PARAM.length));
|
|
92
|
+
if (variant === null) return null;
|
|
93
|
+
variants.push(variant);
|
|
94
|
+
}
|
|
95
|
+
const base = path.slice(0, q);
|
|
96
|
+
return { path: kept.length === 0 ? base : `${base}?${kept.join("&")}`, variants };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** `<block>@<path>=<index>`: the index after the last `=`, the block before the last `@`. */
|
|
100
|
+
function decodeVariant(encoded: string): ForcedVariant | null {
|
|
101
|
+
let raw: string;
|
|
102
|
+
try {
|
|
103
|
+
raw = decodeURIComponent(encoded);
|
|
104
|
+
} catch {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
const eq = raw.lastIndexOf("=");
|
|
108
|
+
const at = raw.lastIndexOf("@", eq);
|
|
109
|
+
if (eq === -1 || at <= 0) return null;
|
|
110
|
+
const index = raw.slice(eq + 1);
|
|
111
|
+
const path = raw.slice(at + 1, eq);
|
|
112
|
+
if (!INDEX_RE.test(index) || (path !== "" && path.split(".").includes(""))) return null;
|
|
113
|
+
return { block: raw.slice(0, at), path, index: Number(index) };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function encodeVariant({ block, path, index }: ForcedVariant): string {
|
|
117
|
+
// encodeURIComponent leaves !'()* as they are; the pointer's path doesn't allow them.
|
|
118
|
+
return encodeURIComponent(`${block}@${path}=${index}`).replace(
|
|
119
|
+
/[!'()*]/g,
|
|
120
|
+
(c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`,
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function plainVariant({ block, path, index }: ForcedVariant): ForcedVariant {
|
|
125
|
+
return { block, path, index };
|
|
57
126
|
}
|
|
58
127
|
|
|
59
128
|
function normalizeHost(authority: string): string | null {
|
package/src/v8/errors.ts
CHANGED
package/src/v8/fetch.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* has no telemetry destination. Nothing about a request's body, headers or
|
|
10
10
|
* query string is recorded.
|
|
11
11
|
*/
|
|
12
|
-
import { currentTelemetry, describe, newTraceId } from "./telemetry";
|
|
12
|
+
import { currentTelemetry, describe, newTraceId } from "./telemetry.ts";
|
|
13
13
|
|
|
14
14
|
interface InstrumentedFetchOptions {
|
|
15
15
|
/** The provider label, e.g. "vtex", "acme-search". */
|
package/src/v8/identity.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* keys go into the global symbol registry, so they're derived from the
|
|
4
4
|
* configuration and never carry a secret.
|
|
5
5
|
*/
|
|
6
|
-
import type { Loader, Snapshot } from "./types";
|
|
6
|
+
import type { Loader, Snapshot } from "./types.ts";
|
|
7
7
|
|
|
8
8
|
const OBJECT_IDS = Symbol.for("decocms.blocks.cms-loader-ids");
|
|
9
9
|
|