@mszr/idb-dux 1.0.0
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/LICENSE +194 -0
- package/README.md +84 -0
- package/dist/commonjs/admin/index.d.ts +18 -0
- package/dist/commonjs/admin/index.d.ts.map +1 -0
- package/dist/commonjs/admin/index.js +31 -0
- package/dist/commonjs/admin/index.js.map +1 -0
- package/dist/commonjs/admin/init.d.ts +67 -0
- package/dist/commonjs/admin/init.d.ts.map +1 -0
- package/dist/commonjs/admin/init.js +86 -0
- package/dist/commonjs/admin/init.js.map +1 -0
- package/dist/commonjs/admin/query.d.ts +21 -0
- package/dist/commonjs/admin/query.d.ts.map +1 -0
- package/dist/commonjs/admin/query.js +46 -0
- package/dist/commonjs/admin/query.js.map +1 -0
- package/dist/commonjs/admin/types.d.ts +124 -0
- package/dist/commonjs/admin/types.d.ts.map +1 -0
- package/dist/commonjs/admin/types.js +3 -0
- package/dist/commonjs/admin/types.js.map +1 -0
- package/dist/commonjs/admin/webhooks.d.ts +11 -0
- package/dist/commonjs/admin/webhooks.d.ts.map +1 -0
- package/dist/commonjs/admin/webhooks.js +8 -0
- package/dist/commonjs/admin/webhooks.js.map +1 -0
- package/dist/commonjs/errors.d.ts +13 -0
- package/dist/commonjs/errors.d.ts.map +1 -0
- package/dist/commonjs/errors.js +19 -0
- package/dist/commonjs/errors.js.map +1 -0
- package/dist/commonjs/index.d.ts +13 -0
- package/dist/commonjs/index.d.ts.map +1 -0
- package/dist/commonjs/index.js +29 -0
- package/dist/commonjs/index.js.map +1 -0
- package/dist/commonjs/nuxt/defineAuthSyncHandler.d.ts +15 -0
- package/dist/commonjs/nuxt/defineAuthSyncHandler.d.ts.map +1 -0
- package/dist/commonjs/nuxt/defineAuthSyncHandler.js +44 -0
- package/dist/commonjs/nuxt/defineAuthSyncHandler.js.map +1 -0
- package/dist/commonjs/nuxt/defineServerKit.d.ts +5 -0
- package/dist/commonjs/nuxt/defineServerKit.d.ts.map +1 -0
- package/dist/commonjs/nuxt/defineServerKit.js +49 -0
- package/dist/commonjs/nuxt/defineServerKit.js.map +1 -0
- package/dist/commonjs/nuxt/defineWebhookHandler.d.ts +17 -0
- package/dist/commonjs/nuxt/defineWebhookHandler.d.ts.map +1 -0
- package/dist/commonjs/nuxt/defineWebhookHandler.js +24 -0
- package/dist/commonjs/nuxt/defineWebhookHandler.js.map +1 -0
- package/dist/commonjs/nuxt/index.d.ts +15 -0
- package/dist/commonjs/nuxt/index.d.ts.map +1 -0
- package/dist/commonjs/nuxt/index.js +24 -0
- package/dist/commonjs/nuxt/index.js.map +1 -0
- package/dist/commonjs/nuxt/types.d.ts +54 -0
- package/dist/commonjs/nuxt/types.d.ts.map +1 -0
- package/dist/commonjs/nuxt/types.js +3 -0
- package/dist/commonjs/nuxt/types.js.map +1 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/commonjs/perms/ast.d.ts +98 -0
- package/dist/commonjs/perms/ast.d.ts.map +1 -0
- package/dist/commonjs/perms/ast.js +148 -0
- package/dist/commonjs/perms/ast.js.map +1 -0
- package/dist/commonjs/perms/builder.d.ts +18 -0
- package/dist/commonjs/perms/builder.d.ts.map +1 -0
- package/dist/commonjs/perms/builder.js +260 -0
- package/dist/commonjs/perms/builder.js.map +1 -0
- package/dist/commonjs/perms/context.d.ts +27 -0
- package/dist/commonjs/perms/context.d.ts.map +1 -0
- package/dist/commonjs/perms/context.js +96 -0
- package/dist/commonjs/perms/context.js.map +1 -0
- package/dist/commonjs/perms/index.d.ts +13 -0
- package/dist/commonjs/perms/index.d.ts.map +1 -0
- package/dist/commonjs/perms/index.js +6 -0
- package/dist/commonjs/perms/index.js.map +1 -0
- package/dist/commonjs/perms/types.d.ts +353 -0
- package/dist/commonjs/perms/types.d.ts.map +1 -0
- package/dist/commonjs/perms/types.js +3 -0
- package/dist/commonjs/perms/types.js.map +1 -0
- package/dist/commonjs/perms/validate.d.ts +31 -0
- package/dist/commonjs/perms/validate.d.ts.map +1 -0
- package/dist/commonjs/perms/validate.js +66 -0
- package/dist/commonjs/perms/validate.js.map +1 -0
- package/dist/commonjs/query/constants.d.ts +13 -0
- package/dist/commonjs/query/constants.d.ts.map +1 -0
- package/dist/commonjs/query/constants.js +16 -0
- package/dist/commonjs/query/constants.js.map +1 -0
- package/dist/commonjs/query/defineQuery.d.ts +33 -0
- package/dist/commonjs/query/defineQuery.d.ts.map +1 -0
- package/dist/commonjs/query/defineQuery.js +28 -0
- package/dist/commonjs/query/defineQuery.js.map +1 -0
- package/dist/commonjs/query/index.d.ts +9 -0
- package/dist/commonjs/query/index.d.ts.map +1 -0
- package/dist/commonjs/query/index.js +16 -0
- package/dist/commonjs/query/index.js.map +1 -0
- package/dist/commonjs/query/keys.d.ts +33 -0
- package/dist/commonjs/query/keys.d.ts.map +1 -0
- package/dist/commonjs/query/keys.js +3 -0
- package/dist/commonjs/query/keys.js.map +1 -0
- package/dist/commonjs/query/shapeResult.d.ts +36 -0
- package/dist/commonjs/query/shapeResult.d.ts.map +1 -0
- package/dist/commonjs/query/shapeResult.js +173 -0
- package/dist/commonjs/query/shapeResult.js.map +1 -0
- package/dist/commonjs/query/types.d.ts +187 -0
- package/dist/commonjs/query/types.d.ts.map +1 -0
- package/dist/commonjs/query/types.js +3 -0
- package/dist/commonjs/query/types.js.map +1 -0
- package/dist/commonjs/query/validation.d.ts +61 -0
- package/dist/commonjs/query/validation.d.ts.map +1 -0
- package/dist/commonjs/query/validation.js +3 -0
- package/dist/commonjs/query/validation.js.map +1 -0
- package/dist/commonjs/query/wire.d.ts +13 -0
- package/dist/commonjs/query/wire.d.ts.map +1 -0
- package/dist/commonjs/query/wire.js +77 -0
- package/dist/commonjs/query/wire.js.map +1 -0
- package/dist/commonjs/schema/defineSchema.d.ts +110 -0
- package/dist/commonjs/schema/defineSchema.d.ts.map +1 -0
- package/dist/commonjs/schema/defineSchema.js +72 -0
- package/dist/commonjs/schema/defineSchema.js.map +1 -0
- package/dist/commonjs/schema/fields.d.ts +33 -0
- package/dist/commonjs/schema/fields.d.ts.map +1 -0
- package/dist/commonjs/schema/fields.js +3 -0
- package/dist/commonjs/schema/fields.js.map +1 -0
- package/dist/commonjs/schema/index.d.ts +9 -0
- package/dist/commonjs/schema/index.d.ts.map +1 -0
- package/dist/commonjs/schema/index.js +10 -0
- package/dist/commonjs/schema/index.js.map +1 -0
- package/dist/commonjs/schema/namespace.d.ts +82 -0
- package/dist/commonjs/schema/namespace.d.ts.map +1 -0
- package/dist/commonjs/schema/namespace.js +37 -0
- package/dist/commonjs/schema/namespace.js.map +1 -0
- package/dist/commonjs/schema/register.d.ts +37 -0
- package/dist/commonjs/schema/register.d.ts.map +1 -0
- package/dist/commonjs/schema/register.js +3 -0
- package/dist/commonjs/schema/register.js.map +1 -0
- package/dist/commonjs/schema/singularize.d.ts +45 -0
- package/dist/commonjs/schema/singularize.d.ts.map +1 -0
- package/dist/commonjs/schema/singularize.js +47 -0
- package/dist/commonjs/schema/singularize.js.map +1 -0
- package/dist/commonjs/schema/types.d.ts +39 -0
- package/dist/commonjs/schema/types.d.ts.map +1 -0
- package/dist/commonjs/schema/types.js +3 -0
- package/dist/commonjs/schema/types.js.map +1 -0
- package/dist/commonjs/schema/util.d.ts +11 -0
- package/dist/commonjs/schema/util.d.ts.map +1 -0
- package/dist/commonjs/schema/util.js +3 -0
- package/dist/commonjs/schema/util.js.map +1 -0
- package/dist/commonjs/tx/index.d.ts +4 -0
- package/dist/commonjs/tx/index.d.ts.map +1 -0
- package/dist/commonjs/tx/index.js +11 -0
- package/dist/commonjs/tx/index.js.map +1 -0
- package/dist/commonjs/tx/typedTx.d.ts +15 -0
- package/dist/commonjs/tx/typedTx.d.ts.map +1 -0
- package/dist/commonjs/tx/typedTx.js +54 -0
- package/dist/commonjs/tx/typedTx.js.map +1 -0
- package/dist/commonjs/tx/types.d.ts +104 -0
- package/dist/commonjs/tx/types.d.ts.map +1 -0
- package/dist/commonjs/tx/types.js +3 -0
- package/dist/commonjs/tx/types.js.map +1 -0
- package/dist/commonjs/vue/baseline/InstantDuxDatabase.d.ts +52 -0
- package/dist/commonjs/vue/baseline/InstantDuxDatabase.d.ts.map +1 -0
- package/dist/commonjs/vue/baseline/InstantDuxDatabase.js +157 -0
- package/dist/commonjs/vue/baseline/InstantDuxDatabase.js.map +1 -0
- package/dist/commonjs/vue/baseline/InstantDuxRoom.d.ts +72 -0
- package/dist/commonjs/vue/baseline/InstantDuxRoom.d.ts.map +1 -0
- package/dist/commonjs/vue/baseline/InstantDuxRoom.js +211 -0
- package/dist/commonjs/vue/baseline/InstantDuxRoom.js.map +1 -0
- package/dist/commonjs/vue/baseline/components/Cursor.d.ts +15 -0
- package/dist/commonjs/vue/baseline/components/Cursor.d.ts.map +1 -0
- package/dist/commonjs/vue/baseline/components/Cursor.js +39 -0
- package/dist/commonjs/vue/baseline/components/Cursor.js.map +1 -0
- package/dist/commonjs/vue/baseline/components/Cursors.d.ts +65 -0
- package/dist/commonjs/vue/baseline/components/Cursors.d.ts.map +1 -0
- package/dist/commonjs/vue/baseline/components/Cursors.js +113 -0
- package/dist/commonjs/vue/baseline/components/Cursors.js.map +1 -0
- package/dist/commonjs/vue/baseline/components/auth.d.ts +37 -0
- package/dist/commonjs/vue/baseline/components/auth.d.ts.map +1 -0
- package/dist/commonjs/vue/baseline/components/auth.js +27 -0
- package/dist/commonjs/vue/baseline/components/auth.js.map +1 -0
- package/dist/commonjs/vue/baseline/index.d.ts +11 -0
- package/dist/commonjs/vue/baseline/index.d.ts.map +1 -0
- package/dist/commonjs/vue/baseline/index.js +29 -0
- package/dist/commonjs/vue/baseline/index.js.map +1 -0
- package/dist/commonjs/vue/baseline/useInfiniteQuery.d.ts +19 -0
- package/dist/commonjs/vue/baseline/useInfiniteQuery.d.ts.map +1 -0
- package/dist/commonjs/vue/baseline/useInfiniteQuery.js +65 -0
- package/dist/commonjs/vue/baseline/useInfiniteQuery.js.map +1 -0
- package/dist/commonjs/vue/baseline/utils.d.ts +9 -0
- package/dist/commonjs/vue/baseline/utils.d.ts.map +1 -0
- package/dist/commonjs/vue/baseline/utils.js +29 -0
- package/dist/commonjs/vue/baseline/utils.js.map +1 -0
- package/dist/commonjs/vue/baseline/version.d.ts +3 -0
- package/dist/commonjs/vue/baseline/version.d.ts.map +1 -0
- package/dist/commonjs/vue/baseline/version.js +6 -0
- package/dist/commonjs/vue/baseline/version.js.map +1 -0
- package/dist/commonjs/vue/index.d.ts +21 -0
- package/dist/commonjs/vue/index.d.ts.map +1 -0
- package/dist/commonjs/vue/index.js +31 -0
- package/dist/commonjs/vue/index.js.map +1 -0
- package/dist/commonjs/vue/overlay/db.d.ts +106 -0
- package/dist/commonjs/vue/overlay/db.d.ts.map +1 -0
- package/dist/commonjs/vue/overlay/db.js +105 -0
- package/dist/commonjs/vue/overlay/db.js.map +1 -0
- package/dist/commonjs/vue/overlay/defineDb.d.ts +34 -0
- package/dist/commonjs/vue/overlay/defineDb.d.ts.map +1 -0
- package/dist/commonjs/vue/overlay/defineDb.js +48 -0
- package/dist/commonjs/vue/overlay/defineDb.js.map +1 -0
- package/dist/commonjs/vue/overlay/result.d.ts +29 -0
- package/dist/commonjs/vue/overlay/result.d.ts.map +1 -0
- package/dist/commonjs/vue/overlay/result.js +75 -0
- package/dist/commonjs/vue/overlay/result.js.map +1 -0
- package/dist/commonjs/vue/overlay/rooms/index.d.ts +79 -0
- package/dist/commonjs/vue/overlay/rooms/index.d.ts.map +1 -0
- package/dist/commonjs/vue/overlay/rooms/index.js +28 -0
- package/dist/commonjs/vue/overlay/rooms/index.js.map +1 -0
- package/dist/commonjs/vue/overlay/types.d.ts +73 -0
- package/dist/commonjs/vue/overlay/types.d.ts.map +1 -0
- package/dist/commonjs/vue/overlay/types.js +3 -0
- package/dist/commonjs/vue/overlay/types.js.map +1 -0
- package/dist/commonjs/webhooks/defineWebhookHandlers.d.ts +27 -0
- package/dist/commonjs/webhooks/defineWebhookHandlers.d.ts.map +1 -0
- package/dist/commonjs/webhooks/defineWebhookHandlers.js +33 -0
- package/dist/commonjs/webhooks/defineWebhookHandlers.js.map +1 -0
- package/dist/commonjs/webhooks/index.d.ts +15 -0
- package/dist/commonjs/webhooks/index.d.ts.map +1 -0
- package/dist/commonjs/webhooks/index.js +21 -0
- package/dist/commonjs/webhooks/index.js.map +1 -0
- package/dist/commonjs/webhooks/init.d.ts +13 -0
- package/dist/commonjs/webhooks/init.d.ts.map +1 -0
- package/dist/commonjs/webhooks/init.js +39 -0
- package/dist/commonjs/webhooks/init.js.map +1 -0
- package/dist/commonjs/webhooks/types.d.ts +136 -0
- package/dist/commonjs/webhooks/types.d.ts.map +1 -0
- package/dist/commonjs/webhooks/types.js +3 -0
- package/dist/commonjs/webhooks/types.js.map +1 -0
- package/dist/esm/admin/index.d.ts +18 -0
- package/dist/esm/admin/index.d.ts.map +1 -0
- package/dist/esm/admin/index.js +21 -0
- package/dist/esm/admin/index.js.map +1 -0
- package/dist/esm/admin/init.d.ts +67 -0
- package/dist/esm/admin/init.d.ts.map +1 -0
- package/dist/esm/admin/init.js +81 -0
- package/dist/esm/admin/init.js.map +1 -0
- package/dist/esm/admin/query.d.ts +21 -0
- package/dist/esm/admin/query.d.ts.map +1 -0
- package/dist/esm/admin/query.js +42 -0
- package/dist/esm/admin/query.js.map +1 -0
- package/dist/esm/admin/types.d.ts +124 -0
- package/dist/esm/admin/types.d.ts.map +1 -0
- package/dist/esm/admin/types.js +2 -0
- package/dist/esm/admin/types.js.map +1 -0
- package/dist/esm/admin/webhooks.d.ts +11 -0
- package/dist/esm/admin/webhooks.d.ts.map +1 -0
- package/dist/esm/admin/webhooks.js +5 -0
- package/dist/esm/admin/webhooks.js.map +1 -0
- package/dist/esm/errors.d.ts +13 -0
- package/dist/esm/errors.d.ts.map +1 -0
- package/dist/esm/errors.js +16 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/index.d.ts +13 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +13 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/nuxt/defineAuthSyncHandler.d.ts +15 -0
- package/dist/esm/nuxt/defineAuthSyncHandler.d.ts.map +1 -0
- package/dist/esm/nuxt/defineAuthSyncHandler.js +41 -0
- package/dist/esm/nuxt/defineAuthSyncHandler.js.map +1 -0
- package/dist/esm/nuxt/defineServerKit.d.ts +5 -0
- package/dist/esm/nuxt/defineServerKit.d.ts.map +1 -0
- package/dist/esm/nuxt/defineServerKit.js +46 -0
- package/dist/esm/nuxt/defineServerKit.js.map +1 -0
- package/dist/esm/nuxt/defineWebhookHandler.d.ts +17 -0
- package/dist/esm/nuxt/defineWebhookHandler.d.ts.map +1 -0
- package/dist/esm/nuxt/defineWebhookHandler.js +21 -0
- package/dist/esm/nuxt/defineWebhookHandler.js.map +1 -0
- package/dist/esm/nuxt/index.d.ts +15 -0
- package/dist/esm/nuxt/index.d.ts.map +1 -0
- package/dist/esm/nuxt/index.js +17 -0
- package/dist/esm/nuxt/index.js.map +1 -0
- package/dist/esm/nuxt/types.d.ts +54 -0
- package/dist/esm/nuxt/types.d.ts.map +1 -0
- package/dist/esm/nuxt/types.js +2 -0
- package/dist/esm/nuxt/types.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/perms/ast.d.ts +98 -0
- package/dist/esm/perms/ast.d.ts.map +1 -0
- package/dist/esm/perms/ast.js +140 -0
- package/dist/esm/perms/ast.js.map +1 -0
- package/dist/esm/perms/builder.d.ts +18 -0
- package/dist/esm/perms/builder.d.ts.map +1 -0
- package/dist/esm/perms/builder.js +257 -0
- package/dist/esm/perms/builder.js.map +1 -0
- package/dist/esm/perms/context.d.ts +27 -0
- package/dist/esm/perms/context.d.ts.map +1 -0
- package/dist/esm/perms/context.js +93 -0
- package/dist/esm/perms/context.js.map +1 -0
- package/dist/esm/perms/index.d.ts +13 -0
- package/dist/esm/perms/index.d.ts.map +1 -0
- package/dist/esm/perms/index.js +2 -0
- package/dist/esm/perms/index.js.map +1 -0
- package/dist/esm/perms/types.d.ts +353 -0
- package/dist/esm/perms/types.d.ts.map +1 -0
- package/dist/esm/perms/types.js +2 -0
- package/dist/esm/perms/types.js.map +1 -0
- package/dist/esm/perms/validate.d.ts +31 -0
- package/dist/esm/perms/validate.d.ts.map +1 -0
- package/dist/esm/perms/validate.js +61 -0
- package/dist/esm/perms/validate.js.map +1 -0
- package/dist/esm/query/constants.d.ts +13 -0
- package/dist/esm/query/constants.d.ts.map +1 -0
- package/dist/esm/query/constants.js +13 -0
- package/dist/esm/query/constants.js.map +1 -0
- package/dist/esm/query/defineQuery.d.ts +33 -0
- package/dist/esm/query/defineQuery.d.ts.map +1 -0
- package/dist/esm/query/defineQuery.js +24 -0
- package/dist/esm/query/defineQuery.js.map +1 -0
- package/dist/esm/query/index.d.ts +9 -0
- package/dist/esm/query/index.d.ts.map +1 -0
- package/dist/esm/query/index.js +5 -0
- package/dist/esm/query/index.js.map +1 -0
- package/dist/esm/query/keys.d.ts +33 -0
- package/dist/esm/query/keys.d.ts.map +1 -0
- package/dist/esm/query/keys.js +2 -0
- package/dist/esm/query/keys.js.map +1 -0
- package/dist/esm/query/shapeResult.d.ts +36 -0
- package/dist/esm/query/shapeResult.d.ts.map +1 -0
- package/dist/esm/query/shapeResult.js +168 -0
- package/dist/esm/query/shapeResult.js.map +1 -0
- package/dist/esm/query/types.d.ts +187 -0
- package/dist/esm/query/types.d.ts.map +1 -0
- package/dist/esm/query/types.js +2 -0
- package/dist/esm/query/types.js.map +1 -0
- package/dist/esm/query/validation.d.ts +61 -0
- package/dist/esm/query/validation.d.ts.map +1 -0
- package/dist/esm/query/validation.js +2 -0
- package/dist/esm/query/validation.js.map +1 -0
- package/dist/esm/query/wire.d.ts +13 -0
- package/dist/esm/query/wire.d.ts.map +1 -0
- package/dist/esm/query/wire.js +74 -0
- package/dist/esm/query/wire.js.map +1 -0
- package/dist/esm/schema/defineSchema.d.ts +110 -0
- package/dist/esm/schema/defineSchema.d.ts.map +1 -0
- package/dist/esm/schema/defineSchema.js +69 -0
- package/dist/esm/schema/defineSchema.js.map +1 -0
- package/dist/esm/schema/fields.d.ts +33 -0
- package/dist/esm/schema/fields.d.ts.map +1 -0
- package/dist/esm/schema/fields.js +2 -0
- package/dist/esm/schema/fields.js.map +1 -0
- package/dist/esm/schema/index.d.ts +9 -0
- package/dist/esm/schema/index.d.ts.map +1 -0
- package/dist/esm/schema/index.js +4 -0
- package/dist/esm/schema/index.js.map +1 -0
- package/dist/esm/schema/namespace.d.ts +82 -0
- package/dist/esm/schema/namespace.d.ts.map +1 -0
- package/dist/esm/schema/namespace.js +34 -0
- package/dist/esm/schema/namespace.js.map +1 -0
- package/dist/esm/schema/register.d.ts +37 -0
- package/dist/esm/schema/register.d.ts.map +1 -0
- package/dist/esm/schema/register.js +2 -0
- package/dist/esm/schema/register.js.map +1 -0
- package/dist/esm/schema/singularize.d.ts +45 -0
- package/dist/esm/schema/singularize.d.ts.map +1 -0
- package/dist/esm/schema/singularize.js +44 -0
- package/dist/esm/schema/singularize.js.map +1 -0
- package/dist/esm/schema/types.d.ts +39 -0
- package/dist/esm/schema/types.d.ts.map +1 -0
- package/dist/esm/schema/types.js +2 -0
- package/dist/esm/schema/types.js.map +1 -0
- package/dist/esm/schema/util.d.ts +11 -0
- package/dist/esm/schema/util.d.ts.map +1 -0
- package/dist/esm/schema/util.js +2 -0
- package/dist/esm/schema/util.js.map +1 -0
- package/dist/esm/tx/index.d.ts +4 -0
- package/dist/esm/tx/index.d.ts.map +1 -0
- package/dist/esm/tx/index.js +5 -0
- package/dist/esm/tx/index.js.map +1 -0
- package/dist/esm/tx/typedTx.d.ts +15 -0
- package/dist/esm/tx/typedTx.d.ts.map +1 -0
- package/dist/esm/tx/typedTx.js +51 -0
- package/dist/esm/tx/typedTx.js.map +1 -0
- package/dist/esm/tx/types.d.ts +104 -0
- package/dist/esm/tx/types.d.ts.map +1 -0
- package/dist/esm/tx/types.js +2 -0
- package/dist/esm/tx/types.js.map +1 -0
- package/dist/esm/vue/baseline/InstantDuxDatabase.d.ts +52 -0
- package/dist/esm/vue/baseline/InstantDuxDatabase.d.ts.map +1 -0
- package/dist/esm/vue/baseline/InstantDuxDatabase.js +149 -0
- package/dist/esm/vue/baseline/InstantDuxDatabase.js.map +1 -0
- package/dist/esm/vue/baseline/InstantDuxRoom.d.ts +72 -0
- package/dist/esm/vue/baseline/InstantDuxRoom.d.ts.map +1 -0
- package/dist/esm/vue/baseline/InstantDuxRoom.js +202 -0
- package/dist/esm/vue/baseline/InstantDuxRoom.js.map +1 -0
- package/dist/esm/vue/baseline/components/Cursor.d.ts +15 -0
- package/dist/esm/vue/baseline/components/Cursor.d.ts.map +1 -0
- package/dist/esm/vue/baseline/components/Cursor.js +36 -0
- package/dist/esm/vue/baseline/components/Cursor.js.map +1 -0
- package/dist/esm/vue/baseline/components/Cursors.d.ts +65 -0
- package/dist/esm/vue/baseline/components/Cursors.d.ts.map +1 -0
- package/dist/esm/vue/baseline/components/Cursors.js +107 -0
- package/dist/esm/vue/baseline/components/Cursors.js.map +1 -0
- package/dist/esm/vue/baseline/components/auth.d.ts +37 -0
- package/dist/esm/vue/baseline/components/auth.d.ts.map +1 -0
- package/dist/esm/vue/baseline/components/auth.js +24 -0
- package/dist/esm/vue/baseline/components/auth.js.map +1 -0
- package/dist/esm/vue/baseline/index.d.ts +11 -0
- package/dist/esm/vue/baseline/index.d.ts.map +1 -0
- package/dist/esm/vue/baseline/index.js +10 -0
- package/dist/esm/vue/baseline/index.js.map +1 -0
- package/dist/esm/vue/baseline/useInfiniteQuery.d.ts +19 -0
- package/dist/esm/vue/baseline/useInfiniteQuery.d.ts.map +1 -0
- package/dist/esm/vue/baseline/useInfiniteQuery.js +62 -0
- package/dist/esm/vue/baseline/useInfiniteQuery.js.map +1 -0
- package/dist/esm/vue/baseline/utils.d.ts +9 -0
- package/dist/esm/vue/baseline/utils.d.ts.map +1 -0
- package/dist/esm/vue/baseline/utils.js +25 -0
- package/dist/esm/vue/baseline/utils.js.map +1 -0
- package/dist/esm/vue/baseline/version.d.ts +3 -0
- package/dist/esm/vue/baseline/version.d.ts.map +1 -0
- package/dist/esm/vue/baseline/version.js +4 -0
- package/dist/esm/vue/baseline/version.js.map +1 -0
- package/dist/esm/vue/index.d.ts +21 -0
- package/dist/esm/vue/index.d.ts.map +1 -0
- package/dist/esm/vue/index.js +18 -0
- package/dist/esm/vue/index.js.map +1 -0
- package/dist/esm/vue/overlay/db.d.ts +106 -0
- package/dist/esm/vue/overlay/db.d.ts.map +1 -0
- package/dist/esm/vue/overlay/db.js +101 -0
- package/dist/esm/vue/overlay/db.js.map +1 -0
- package/dist/esm/vue/overlay/defineDb.d.ts +34 -0
- package/dist/esm/vue/overlay/defineDb.d.ts.map +1 -0
- package/dist/esm/vue/overlay/defineDb.js +44 -0
- package/dist/esm/vue/overlay/defineDb.js.map +1 -0
- package/dist/esm/vue/overlay/result.d.ts +29 -0
- package/dist/esm/vue/overlay/result.d.ts.map +1 -0
- package/dist/esm/vue/overlay/result.js +71 -0
- package/dist/esm/vue/overlay/result.js.map +1 -0
- package/dist/esm/vue/overlay/rooms/index.d.ts +79 -0
- package/dist/esm/vue/overlay/rooms/index.d.ts.map +1 -0
- package/dist/esm/vue/overlay/rooms/index.js +25 -0
- package/dist/esm/vue/overlay/rooms/index.js.map +1 -0
- package/dist/esm/vue/overlay/types.d.ts +73 -0
- package/dist/esm/vue/overlay/types.d.ts.map +1 -0
- package/dist/esm/vue/overlay/types.js +2 -0
- package/dist/esm/vue/overlay/types.js.map +1 -0
- package/dist/esm/webhooks/defineWebhookHandlers.d.ts +27 -0
- package/dist/esm/webhooks/defineWebhookHandlers.d.ts.map +1 -0
- package/dist/esm/webhooks/defineWebhookHandlers.js +30 -0
- package/dist/esm/webhooks/defineWebhookHandlers.js.map +1 -0
- package/dist/esm/webhooks/index.d.ts +15 -0
- package/dist/esm/webhooks/index.d.ts.map +1 -0
- package/dist/esm/webhooks/index.js +14 -0
- package/dist/esm/webhooks/index.js.map +1 -0
- package/dist/esm/webhooks/init.d.ts +13 -0
- package/dist/esm/webhooks/init.d.ts.map +1 -0
- package/dist/esm/webhooks/init.js +36 -0
- package/dist/esm/webhooks/init.js.map +1 -0
- package/dist/esm/webhooks/types.d.ts +136 -0
- package/dist/esm/webhooks/types.d.ts.map +1 -0
- package/dist/esm/webhooks/types.js +2 -0
- package/dist/esm/webhooks/types.js.map +1 -0
- package/package.json +149 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/perms/types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * The perms-domain types: the schema-aware context every callback receives,\n * the ref-path machinery, the allow/fields/bind/stage shapes, the chainable\n * builders, and the compiled `IdbPerms` output.\n *\n * The context is **entity-rooted with current unmarked** (conventions §10):\n * `e`/`ef`/`er` read the current entity (`data.*`), `eu`/`euf` the updated one\n * (`newData.*`, update only), `el`/`elf`/`elr` the linked one (`linkedData.*`,\n * link/unlink only). Action-only values exist only in the matching action\n * callback, so misusing one (`eu` in `view`) fails at the cursor.\n */\nimport type { DataAttrDef, InstantRules } from '@instantdb/core'\nimport type { IdbSchema } from '../schema/defineSchema.js'\nimport type {\n AttrsOf,\n AttrValue,\n FieldKeys,\n LinkLabels,\n LinkTarget,\n} from '../schema/fields.js'\nimport type { IdbRegisteredSchema } from '../schema/register.js'\nimport type { IdbNamespaceName } from '../schema/types.js'\nimport type { Expand } from '../schema/util.js'\nimport type { Expr, ExprArg, ListExpr } from './ast.js'\n\n// ==========\n// field + ref resolution\n\n/** The authoring value type of a field. */\nexport type FieldValue<S extends IdbSchema, NS extends string, K extends string>\n = K extends 'id' ? string\n : K extends FieldKeys<S, NS> ? AttrValue<AttrsOf<S, NS>[K]> : never\n\n/** Property-access view of an entity: `id` plus every field, each an `Expr`. */\nexport type EntityExpr<S extends IdbSchema, NS extends string> = Expand<\n { id: Expr<string> } & {\n [K in FieldKeys<S, NS>]: Expr<FieldValue<S, NS, K>>\n }\n>\n\ntype RefDepth = readonly unknown[]\n/** Ref-path autocomplete spans up to four link hops (spec §7), then `raw`. */\ntype RefMaxHops = 4\ntype NextRef<D extends RefDepth> = [...D, unknown]\n\ntype RefAttr<S extends IdbSchema, NS extends string> = FieldKeys<S, NS> | 'id'\n\n/**\n * Every valid ref path from a namespace: one or more link hops ending in an\n * attribute (`'memberships.user.id'`). Capped at `RefMaxHops` so the union\n * stays tractable; deeper paths use `raw`.\n */\nexport type RefPath<\n S extends IdbSchema,\n NS extends string,\n D extends RefDepth = [],\n> = D['length'] extends RefMaxHops\n ? never\n : {\n [L in LinkLabels<S, NS>]:\n | `${L}.${RefAttr<S, LinkTarget<S, NS, L>>}`\n | `${L}.${RefPath<S, LinkTarget<S, NS, L>, NextRef<D>>}`\n }[LinkLabels<S, NS>]\n\n/** The value type a ref path terminates in — a list of these is what `er` returns. */\nexport type RefTerminal<\n S extends IdbSchema,\n NS extends string,\n P extends string,\n> = P extends `${infer L}.${infer Rest}`\n ? L extends LinkLabels<S, NS>\n ? Rest extends RefAttr<S, LinkTarget<S, NS, L>>\n ? FieldValue<S, LinkTarget<S, NS, L>, Rest>\n : RefTerminal<S, LinkTarget<S, NS, L>, Rest>\n : never\n : never\n\n/** Auth refs start from `$users`, spelled `$user.`-prefixed (Instant's form). */\nexport type AuthRefPath<S extends IdbSchema> = `$user.${RefPath<S, '$users'>}`\ntype AuthRefTerminal<S extends IdbSchema, P extends string>\n = P extends `$user.${infer Rest}` ? RefTerminal<S, '$users', Rest> : never\n\n// ==========\n// ruleParams resolution\n\ntype RuleParamDefs<S extends IdbSchema, NS extends string>\n = NS extends keyof S['$dux']['namespaces']\n ? S['$dux']['namespaces'][NS]['ruleParams'] extends infer RP\n ? RP extends Record<string, DataAttrDef<any, any, any, any>>\n ? RP\n : {}\n : {}\n : {}\n\ntype RuleParamKeys<S extends IdbSchema, NS extends string> = keyof RuleParamDefs<S, NS> & string\ntype RuleParamValue<S extends IdbSchema, NS extends string, K extends string>\n = K extends keyof RuleParamDefs<S, NS> ? AttrValue<RuleParamDefs<S, NS>[K]> : never\n\n// ==========\n// the fixed CEL globals\n\n/** The authenticated user — a `$users` entity, plus `id`, read as `auth.*`. */\nexport type AuthExpr<S extends IdbSchema>\n = '$users' extends IdbNamespaceName<S>\n ? EntityExpr<S, '$users'>\n : { id: Expr<string> }\n\n/** Request metadata always in scope (`request.*`). */\nexport interface RequestExpr {\n time: Expr<Date>\n ip: Expr<string>\n origin: Expr<string>\n}\n\n/** The create/update request: the common metadata plus the modified-field set. */\nexport interface WriteRequestExpr extends RequestExpr {\n modifiedFields: ListExpr<string>\n}\n\n/** Functional composition — best for nested or n-ary rules (spec §8). */\nexport interface Fns {\n and: (...exprs: ExprArg<boolean>[]) => Expr<boolean>\n or: (...exprs: ExprArg<boolean>[]) => Expr<boolean>\n not: (expr: ExprArg<boolean>) => Expr<boolean>\n eq: <T>(a: ExprArg<T>, b: ExprArg<T>) => Expr<boolean>\n neq: <T>(a: ExprArg<T>, b: ExprArg<T>) => Expr<boolean>\n gt: <T>(a: ExprArg<T>, b: ExprArg<T>) => Expr<boolean>\n gte: <T>(a: ExprArg<T>, b: ExprArg<T>) => Expr<boolean>\n lt: <T>(a: ExprArg<T>, b: ExprArg<T>) => Expr<boolean>\n lte: <T>(a: ExprArg<T>, b: ExprArg<T>) => Expr<boolean>\n in: <T>(item: ExprArg<T>, list: readonly ExprArg<T>[] | ListExpr<T>) => Expr<boolean>\n contains: <T>(list: readonly ExprArg<T>[] | ListExpr<T>, item: ExprArg<T>) => Expr<boolean>\n size: (value: ListExpr<any> | ExprArg<string>) => Expr<number>\n list: <T>(...values: ExprArg<T>[]) => ListExpr<T>\n str: (value: ExprArg<string>) => Expr<string>\n num: (value: ExprArg<number>) => Expr<number>\n bool: (value: ExprArg<boolean>) => Expr<boolean>\n null: () => Expr<null>\n}\n\n/** Configured rate-limit buckets, used as `rl.bucket.limit(key)`. */\nexport type RateLimitCtx<RL> = {\n [K in keyof RL]: { limit: (key: ExprArg<unknown>) => Expr<boolean> }\n}\n\n/** How a bucket refills — mirrors Instant's `$rateLimits` refill shape (spec §11). */\nexport interface IdbPermsRateLimitRefill {\n amount?: number\n period?: string\n type?: 'interval' | 'greedy'\n}\n\n/** One token-bucket limit. */\nexport interface IdbPermsRateLimitLimit {\n capacity: number\n refill?: IdbPermsRateLimitRefill\n}\n\n/** A named rate-limit bucket — used in rules via `rl.<name>.limit(key)`. */\nexport interface IdbPermsRateLimit {\n limits: IdbPermsRateLimitLimit[]\n}\n\n/** The `$rateLimits` configuration map (structurally Instant's shape). */\nexport type IdbPermsRateLimits = Record<string, IdbPermsRateLimit>\n\n// ==========\n// contexts\n\n/** The common context — every callback's baseline (spec §6). */\nexport interface CommonCtx<\n S extends IdbSchema,\n NS extends string,\n St,\n Bn,\n RL,\n> {\n auth: AuthExpr<S>\n ar: <P extends AuthRefPath<S>>(path: P) => ListExpr<AuthRefTerminal<S, P>>\n e: EntityExpr<S, NS>\n ef: <K extends FieldKeys<S, NS>>(key: K) => Expr<FieldValue<S, NS, K>>\n er: <P extends RefPath<S, NS>>(path: P) => ListExpr<RefTerminal<S, NS, P>>\n rp: <K extends RuleParamKeys<S, NS>>(key: K) => Expr<RuleParamValue<S, NS, K>>\n req: RequestExpr\n f: Fns\n ops: Fns\n raw: <T = boolean>(cel: string) => Expr<T>\n rl: RateLimitCtx<RL>\n s: St\n b: Bn\n}\n\n/** Create/update context — common plus `request.modifiedFields`. */\nexport type WriteCtx<S extends IdbSchema, NS extends string, St, Bn, RL>\n = Omit<CommonCtx<S, NS, St, Bn, RL>, 'req'> & { req: WriteRequestExpr }\n\n/** Update context — write context plus the updated entity (`newData.*`). */\nexport type UpdateCtx<S extends IdbSchema, NS extends string, St, Bn, RL>\n = WriteCtx<S, NS, St, Bn, RL> & {\n eu: EntityExpr<S, NS>\n euf: <K extends FieldKeys<S, NS>>(key: K) => Expr<FieldValue<S, NS, K>>\n }\n\n/** Link/unlink context — common plus the linked entity, typed per link label. */\nexport type LinkCtx<S extends IdbSchema, NS extends string, L extends string, St, Bn, RL>\n = CommonCtx<S, NS, St, Bn, RL> & {\n el: EntityExpr<S, LinkTarget<S, NS, L>>\n elf: <K extends FieldKeys<S, LinkTarget<S, NS, L>>>(key: K) => Expr<FieldValue<S, LinkTarget<S, NS, L>, K>>\n elr: <P extends RefPath<S, LinkTarget<S, NS, L>>>(path: P) => ListExpr<RefTerminal<S, LinkTarget<S, NS, L>, P>>\n }\n\n/** The loose context for `.defaults` — no namespace, so reads are string-keyed. */\nexport interface DefaultCtx<S extends IdbSchema, St, Bn, RL> {\n auth: AuthExpr<S>\n ar: <P extends AuthRefPath<S>>(path: P) => ListExpr<AuthRefTerminal<S, P>>\n ef: (key: string) => Expr<unknown>\n er: (path: string) => ListExpr<unknown>\n rp: (key: string) => Expr<unknown>\n req: RequestExpr\n f: Fns\n ops: Fns\n raw: <T = boolean>(cel: string) => Expr<T>\n rl: RateLimitCtx<RL>\n s: St\n b: Bn\n}\n\n/** The narrow context for `.attrs` — no entity, no refs (spec §5). */\nexport interface AttrsCtx<S extends IdbSchema, RL> {\n auth: AuthExpr<S>\n ar: <P extends AuthRefPath<S>>(path: P) => ListExpr<AuthRefTerminal<S, P>>\n req: RequestExpr\n f: Fns\n ops: Fns\n raw: <T = boolean>(cel: string) => Expr<T>\n rl: RateLimitCtx<RL>\n}\n\n// ==========\n// action scopes — what stageFor/bindFor accumulate\n\n/** The four whole-entity actions a `stageFor`/`bindFor` can target. */\nexport type EntityAction = 'view' | 'create' | 'update' | 'delete'\n/** The two link-label actions. */\nexport type LinkAction = 'link' | 'unlink'\n\n/** One action's accumulated action-specific staged (`s`) and bind (`b`) names. */\nexport interface Scope { s: object, b: object }\ninterface EmptyScope { s: {}, b: {} }\n\n/**\n * The action-specific names a namespace builder has accumulated — threaded\n * through the builder's type so each appears *only* in its own action's\n * callback. Whole-entity actions hold one scope; link/unlink hold one per label.\n */\nexport interface ActionScopes {\n view: Scope\n create: Scope\n update: Scope\n delete: Scope\n link: Record<string, Scope>\n unlink: Record<string, Scope>\n}\n\n/** The starting scopes — nothing action-specific yet. */\nexport interface EmptyScopes {\n view: EmptyScope\n create: EmptyScope\n update: EmptyScope\n delete: EmptyScope\n link: {}\n unlink: {}\n}\n\ntype LinkScopeOf<AX extends ActionScopes, D extends LinkAction, L extends string>\n = L extends keyof AX[D] ? AX[D][L] : EmptyScope\n\ninterface StageScope<Sc extends Scope, O> { s: Expand<Sc['s'] & O>, b: Sc['b'] }\ninterface BindScope<Sc extends Scope, O> { s: Sc['s'], b: Expand<Sc['b'] & O> }\n\n// The full ActionScopes is rebuilt explicitly (rather than Omit + re-add) so the\n// result is statically known to keep all six keys, satisfying the constraint\n// even while `A` is still a generic.\ninterface AddStage<AX extends ActionScopes, A extends EntityAction, O> {\n view: A extends 'view' ? StageScope<AX['view'], O> : AX['view']\n create: A extends 'create' ? StageScope<AX['create'], O> : AX['create']\n update: A extends 'update' ? StageScope<AX['update'], O> : AX['update']\n delete: A extends 'delete' ? StageScope<AX['delete'], O> : AX['delete']\n link: AX['link']\n unlink: AX['unlink']\n}\ninterface AddBind<AX extends ActionScopes, A extends EntityAction, O> {\n view: A extends 'view' ? BindScope<AX['view'], O> : AX['view']\n create: A extends 'create' ? BindScope<AX['create'], O> : AX['create']\n update: A extends 'update' ? BindScope<AX['update'], O> : AX['update']\n delete: A extends 'delete' ? BindScope<AX['delete'], O> : AX['delete']\n link: AX['link']\n unlink: AX['unlink']\n}\ninterface AddLinkStage<AX extends ActionScopes, D extends LinkAction, L extends string, O> {\n view: AX['view']\n create: AX['create']\n update: AX['update']\n delete: AX['delete']\n link: D extends 'link' ? AX['link'] & { [P in L]: StageScope<LinkScopeOf<AX, 'link', L>, O> } : AX['link']\n unlink: D extends 'unlink' ? AX['unlink'] & { [P in L]: StageScope<LinkScopeOf<AX, 'unlink', L>, O> } : AX['unlink']\n}\ninterface AddLinkBind<AX extends ActionScopes, D extends LinkAction, L extends string, O> {\n view: AX['view']\n create: AX['create']\n update: AX['update']\n delete: AX['delete']\n link: D extends 'link' ? AX['link'] & { [P in L]: BindScope<LinkScopeOf<AX, 'link', L>, O> } : AX['link']\n unlink: D extends 'unlink' ? AX['unlink'] & { [P in L]: BindScope<LinkScopeOf<AX, 'unlink', L>, O> } : AX['unlink']\n}\n\n/** The context a whole-entity action callback (and its `stageFor`/`bindFor`) sees. */\nexport type ActionCtx<S extends IdbSchema, NS extends string, St, Bn, RL, A extends EntityAction>\n = A extends 'update'\n ? UpdateCtx<S, NS, St, Bn, RL>\n : A extends 'create'\n ? WriteCtx<S, NS, St, Bn, RL>\n : CommonCtx<S, NS, St, Bn, RL>\n\n// ==========\n// allow / fields / bind / stage shapes\n\n/** A rule value: a boolean, an expression, or a callback returning one. */\nexport type Rule<Ctx> = boolean | Expr<boolean> | ((ctx: Ctx) => boolean | Expr<boolean>)\n\n/**\n * The allow block for a namespace. Each action's callback sees the common\n * scope plus that action's `stageFor`/`bindFor` names (and, for link/unlink,\n * the per-label ones) — so action-specific aliases resolve only where they\n * make sense.\n */\nexport interface AllowBlock<S extends IdbSchema, NS extends string, St, Bn, RL, AX extends ActionScopes = EmptyScopes> {\n view?: Rule<CommonCtx<S, NS, St & AX['view']['s'], Bn & AX['view']['b'], RL>>\n create?: Rule<WriteCtx<S, NS, St & AX['create']['s'], Bn & AX['create']['b'], RL>>\n update?: Rule<UpdateCtx<S, NS, St & AX['update']['s'], Bn & AX['update']['b'], RL>>\n delete?: Rule<CommonCtx<S, NS, St & AX['delete']['s'], Bn & AX['delete']['b'], RL>>\n link?: {\n [L in LinkLabels<S, NS>]?: Rule<LinkCtx<S, NS, L, St & LinkScopeOf<AX, 'link', L>['s'], Bn & LinkScopeOf<AX, 'link', L>['b'], RL>>\n }\n unlink?: {\n [L in LinkLabels<S, NS>]?: Rule<LinkCtx<S, NS, L, St & LinkScopeOf<AX, 'unlink', L>['s'], Bn & LinkScopeOf<AX, 'unlink', L>['b'], RL>>\n }\n}\n\nexport type AllowInput<S extends IdbSchema, NS extends string, St, Bn, RL, AX extends ActionScopes = EmptyScopes>\n = AllowBlock<S, NS, St, Bn, RL, AX> | ((ctx: CommonCtx<S, NS, St, Bn, RL>) => AllowBlock<S, NS, St, Bn, RL, AX>)\n\n/** Field-level rules — every field except `id`. */\nexport type FieldsBlock<S extends IdbSchema, NS extends string> = {\n [F in Exclude<FieldKeys<S, NS>, 'id'>]?: boolean | Expr<boolean>\n}\n\nexport type FieldsInput<S extends IdbSchema, NS extends string, St, Bn, RL>\n = FieldsBlock<S, NS> | ((ctx: CommonCtx<S, NS, St, Bn, RL>) => FieldsBlock<S, NS>)\n\n/** A stage/bind callback returns named expressions. */\nexport type NameObj = Record<string, Expr<any>>\n\n/**\n * Maps duplicate names (already in `Existing`) to a diagnostic and leaves\n * valid names untouched (intersection identity), so a clash lands on the\n * offending key with an actionable message.\n */\nexport type NoDuplicateNames<O, Existing> = {\n [K in keyof O]: K extends keyof Existing\n ? `QERR_PERMS_DUPLICATE_NAME: ${K & string} is already defined — use .overrideStage/.overrideBind to replace it`\n : unknown\n}\n\n// ==========\n// the default allow block (loose, with $default)\n\nexport interface DefaultAllowBlock<S extends IdbSchema, St, Bn, RL> {\n $default?: Rule<DefaultCtx<S, St, Bn, RL>>\n view?: Rule<DefaultCtx<S, St, Bn, RL>>\n create?: Rule<DefaultCtx<S, St, Bn, RL>>\n update?: Rule<DefaultCtx<S, St, Bn, RL>>\n delete?: Rule<DefaultCtx<S, St, Bn, RL>>\n}\n\nexport type DefaultAllowInput<S extends IdbSchema, St, Bn, RL>\n = DefaultAllowBlock<S, St, Bn, RL> | ((ctx: DefaultCtx<S, St, Bn, RL>) => DefaultAllowBlock<S, St, Bn, RL>)\n\n// ==========\n// builders\n\n/** The namespace builder — `ns` in `.namespaces({})` (spec §4). */\nexport interface NsBuilder<\n S extends IdbSchema,\n NS extends string,\n St = {},\n Bn = {},\n RL = {},\n AX extends ActionScopes = EmptyScopes,\n> {\n stage: <O extends NameObj>(\n fn: (ctx: CommonCtx<S, NS, St, Bn, RL>) => O & NoDuplicateNames<O, St & Bn>,\n ) => NsBuilder<S, NS, Expand<St & O>, Bn, RL, AX>\n overrideStage: <O extends NameObj>(\n fn: (ctx: CommonCtx<S, NS, St, Bn, RL>) => O,\n ) => NsBuilder<S, NS, Expand<St & O>, Bn, RL, AX>\n bind: <O extends NameObj>(\n fn: (ctx: CommonCtx<S, NS, St, Bn, RL>) => O & NoDuplicateNames<O, St & Bn>,\n ) => NsBuilder<S, NS, St, Expand<Bn & O>, RL, AX>\n overrideBind: <O extends NameObj>(\n fn: (ctx: CommonCtx<S, NS, St, Bn, RL>) => O,\n ) => NsBuilder<S, NS, St, Expand<Bn & O>, RL, AX>\n /**\n * Action-specific staged values — authoring-only, visible only in the\n * matching action's callback. For link/unlink, pass the label too (spec §9).\n */\n stageFor: {\n <A extends EntityAction, O extends NameObj>(\n action: A,\n fn: (ctx: ActionCtx<S, NS, St & AX[A]['s'], Bn & AX[A]['b'], RL, A>) => O & NoDuplicateNames<O, St & Bn>,\n ): NsBuilder<S, NS, St, Bn, RL, AddStage<AX, A, O>>\n <D extends LinkAction, L extends LinkLabels<S, NS>, O extends NameObj>(\n dir: D,\n label: L,\n fn: (ctx: LinkCtx<S, NS, L, St & LinkScopeOf<AX, D, L>['s'], Bn & LinkScopeOf<AX, D, L>['b'], RL>) => O & NoDuplicateNames<O, St & Bn>,\n ): NsBuilder<S, NS, St, Bn, RL, AddLinkStage<AX, D, L, O>>\n }\n /**\n * Action-specific bind aliases — emitted into the namespace `bind` block\n * (the backend evaluates each only where referenced), visible only in the\n * matching action's callback (spec §9).\n */\n bindFor: {\n <A extends EntityAction, O extends NameObj>(\n action: A,\n fn: (ctx: ActionCtx<S, NS, St & AX[A]['s'], Bn & AX[A]['b'], RL, A>) => O & NoDuplicateNames<O, St & Bn>,\n ): NsBuilder<S, NS, St, Bn, RL, AddBind<AX, A, O>>\n <D extends LinkAction, L extends LinkLabels<S, NS>, O extends NameObj>(\n dir: D,\n label: L,\n fn: (ctx: LinkCtx<S, NS, L, St & LinkScopeOf<AX, D, L>['s'], Bn & LinkScopeOf<AX, D, L>['b'], RL>) => O & NoDuplicateNames<O, St & Bn>,\n ): NsBuilder<S, NS, St, Bn, RL, AddLinkBind<AX, D, L, O>>\n }\n allow: (input: AllowInput<S, NS, St, Bn, RL, AX>) => NsBuilder<S, NS, St, Bn, RL, AX>\n fields: (input: FieldsInput<S, NS, St, Bn, RL>) => NsBuilder<S, NS, St, Bn, RL, AX>\n}\n\n/** The defaults builder — `d` in `.defaults()` (spec §5). */\nexport interface DefaultsBuilder<\n S extends IdbSchema,\n St = {},\n Bn = {},\n RL = {},\n> {\n stage: <O extends NameObj>(\n fn: (ctx: DefaultCtx<S, St, Bn, RL>) => O & NoDuplicateNames<O, St & Bn>,\n ) => DefaultsBuilder<S, Expand<St & O>, Bn, RL>\n bind: <O extends NameObj>(\n fn: (ctx: DefaultCtx<S, St, Bn, RL>) => O & NoDuplicateNames<O, St & Bn>,\n ) => DefaultsBuilder<S, St, Expand<Bn & O>, RL>\n allow: (input: DefaultAllowInput<S, St, Bn, RL>) => DefaultsBuilder<S, St, Bn, RL>\n /**\n * Phantom carriers so `.defaults` can infer the accumulated maps.\n * @internal\n */\n readonly __staged?: St\n readonly __binds?: Bn\n}\n\n/** The attrs builder — create-only (spec §5). */\nexport interface AttrsBuilder<S extends IdbSchema, RL = {}> {\n allow: (input:\n | { create?: boolean | Expr<boolean> }\n | ((ctx: AttrsCtx<S, RL>) => { create?: boolean | Expr<boolean> })) => AttrsBuilder<S, RL>\n}\n\ntype DefaultStagedOf<D> = D extends DefaultsBuilder<any, infer St, any, any> ? St : {}\ntype DefaultBindsOf<D> = D extends DefaultsBuilder<any, any, infer Bn, any> ? Bn : {}\n\n/** The `.namespaces({})` input — keys are schema namespaces, callbacks build each. */\nexport type NamespacesInput<S extends IdbSchema, St, Bn, RL> = {\n [NS in IdbNamespaceName<S>]?: (\n ns: NsBuilder<S, NS, St, Bn, RL>,\n ) => NsBuilder<S, NS, any, any, RL, any>\n}\n\n/** The top-level builder returned by `definePerms` (spec §3). */\nexport interface PermsBuilder<\n S extends IdbSchema,\n St = {},\n Bn = {},\n RL = {},\n> {\n attrs: (fn: (a: AttrsBuilder<S, RL>) => AttrsBuilder<S, RL>) => PermsBuilder<S, St, Bn, RL>\n defaults: <D extends DefaultsBuilder<S, any, any, RL>>(\n fn: (d: DefaultsBuilder<S, {}, {}, RL>) => D,\n ) => PermsBuilder<S, DefaultStagedOf<D>, DefaultBindsOf<D>, RL>\n rateLimits: <R extends IdbPermsRateLimits>(config: R) => PermsBuilder<S, St, Bn, R>\n namespaces: (map: NamespacesInput<S, St, Bn, RL>) => PermsBuilder<S, St, Bn, RL>\n compile: () => IdbPerms<S>\n}\n\n// ==========\n// output\n\n/**\n * The compiled rules object — plain CEL strings, structurally assignable to\n * the official `InstantRules<S>` (so CLI push and platform `pushPerms` accept\n * it unchanged).\n */\nexport type IdbPerms<S extends IdbSchema = IdbRegisteredSchema> = InstantRules<S>\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime schema validation — the dev-time assertions `definePerms(schema)`
|
|
3
|
+
* adds on top of the type layer. The types are the primary safety net
|
|
4
|
+
* (principle 3); these catch the cases a dynamically-built rules object can
|
|
5
|
+
* smuggle past the compiler, and turn a silent bad-CEL push into a clear throw
|
|
6
|
+
* at author time.
|
|
7
|
+
*
|
|
8
|
+
* When no schema value is passed (`definePerms()` / `definePerms<S>()`), every
|
|
9
|
+
* check is a no-op — there is nothing to validate against.
|
|
10
|
+
*/
|
|
11
|
+
import type { IdbSchema } from '../schema/defineSchema.js';
|
|
12
|
+
/** The per-callback validation hooks the context wires into its helpers. */
|
|
13
|
+
export interface Validator {
|
|
14
|
+
field: (key: string) => void;
|
|
15
|
+
ref: (path: string) => void;
|
|
16
|
+
ruleParam: (key: string) => void;
|
|
17
|
+
authRef: (path: string) => void;
|
|
18
|
+
linkedField: (key: string) => void;
|
|
19
|
+
linkedRef: (path: string) => void;
|
|
20
|
+
}
|
|
21
|
+
/** The inert validator — used in type-only mode. */
|
|
22
|
+
export declare const noValidate: Validator;
|
|
23
|
+
/** Does the schema declare this namespace? */
|
|
24
|
+
export declare function namespaceExists(schema: IdbSchema, ns: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Build the validator for a namespace callback. `linkTarget` is set only when
|
|
27
|
+
* resolving a specific link/unlink rule, so `el`/`elr` validate against the
|
|
28
|
+
* linked namespace.
|
|
29
|
+
*/
|
|
30
|
+
export declare function makeValidator(schema: IdbSchema, ns: string, linkTarget?: string): Validator;
|
|
31
|
+
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../src/perms/validate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAE1D,4EAA4E;AAC5E,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;IAC5B,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IAC3B,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;IAChC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IAC/B,WAAW,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;IAClC,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;CAClC;AAED,oDAAoD;AACpD,eAAO,MAAM,UAAU,EAAE,SAOxB,CAAA;AAgCD,8CAA8C;AAC9C,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAEtE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,SAAS,EACjB,EAAE,EAAE,MAAM,EACV,UAAU,CAAC,EAAE,MAAM,GAClB,SAAS,CAeX"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.noValidate = void 0;
|
|
4
|
+
exports.namespaceExists = namespaceExists;
|
|
5
|
+
exports.makeValidator = makeValidator;
|
|
6
|
+
/** The inert validator — used in type-only mode. */
|
|
7
|
+
exports.noValidate = {
|
|
8
|
+
field: () => { },
|
|
9
|
+
ref: () => { },
|
|
10
|
+
ruleParam: () => { },
|
|
11
|
+
authRef: () => { },
|
|
12
|
+
linkedField: () => { },
|
|
13
|
+
linkedRef: () => { },
|
|
14
|
+
};
|
|
15
|
+
function fail(message) {
|
|
16
|
+
throw new Error(`QERR_PERMS_SCHEMA: ${message}`);
|
|
17
|
+
}
|
|
18
|
+
function fieldExists(schema, ns, key) {
|
|
19
|
+
if (key === 'id')
|
|
20
|
+
return true;
|
|
21
|
+
return Boolean(schema.entities[ns]?.attrs?.[key]);
|
|
22
|
+
}
|
|
23
|
+
function ruleParamExists(schema, ns, key) {
|
|
24
|
+
return Boolean(schema.$dux?.namespaces?.[ns]?.ruleParams?.[key]);
|
|
25
|
+
}
|
|
26
|
+
/** Walk a `link(.link)*.attr` path; the terminal must be an attribute. */
|
|
27
|
+
function refValid(schema, ns, path) {
|
|
28
|
+
const parts = path.split('.');
|
|
29
|
+
const terminal = parts.pop();
|
|
30
|
+
if (terminal === undefined)
|
|
31
|
+
return false;
|
|
32
|
+
let current = ns;
|
|
33
|
+
for (const label of parts) {
|
|
34
|
+
const target = schema.entities[current]?.links?.[label]?.entityName;
|
|
35
|
+
if (!target)
|
|
36
|
+
return false;
|
|
37
|
+
current = target;
|
|
38
|
+
}
|
|
39
|
+
return fieldExists(schema, current, terminal);
|
|
40
|
+
}
|
|
41
|
+
/** Does the schema declare this namespace? */
|
|
42
|
+
function namespaceExists(schema, ns) {
|
|
43
|
+
return Boolean(schema.entities[ns]);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Build the validator for a namespace callback. `linkTarget` is set only when
|
|
47
|
+
* resolving a specific link/unlink rule, so `el`/`elr` validate against the
|
|
48
|
+
* linked namespace.
|
|
49
|
+
*/
|
|
50
|
+
function makeValidator(schema, ns, linkTarget) {
|
|
51
|
+
return {
|
|
52
|
+
field: key => fieldExists(schema, ns, key)
|
|
53
|
+
|| fail(`'${key}' is not a field on '${ns}'`),
|
|
54
|
+
ref: path => refValid(schema, ns, path)
|
|
55
|
+
|| fail(`'${path}' is not a valid ref path from '${ns}'`),
|
|
56
|
+
ruleParam: key => ruleParamExists(schema, ns, key)
|
|
57
|
+
|| fail(`'${key}' is not a declared ruleParam on '${ns}'`),
|
|
58
|
+
authRef: path => refValid(schema, '$users', path.replace(/^\$user\./, ''))
|
|
59
|
+
|| fail(`'${path}' is not a valid auth ref path`),
|
|
60
|
+
linkedField: key => (linkTarget && fieldExists(schema, linkTarget, key))
|
|
61
|
+
|| fail(`'${key}' is not a field on linked namespace '${linkTarget}'`),
|
|
62
|
+
linkedRef: path => (linkTarget && refValid(schema, linkTarget, path))
|
|
63
|
+
|| fail(`'${path}' is not a valid ref path from linked namespace '${linkTarget}'`),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../../src/perms/validate.ts"],"names":[],"mappings":";;;AA+DA,0CAEC;AAOD,sCAmBC;AArED,oDAAoD;AACvC,QAAA,UAAU,GAAc;IACnC,KAAK,EAAE,GAAG,EAAE,GAAE,CAAC;IACf,GAAG,EAAE,GAAG,EAAE,GAAE,CAAC;IACb,SAAS,EAAE,GAAG,EAAE,GAAE,CAAC;IACnB,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC;IACjB,WAAW,EAAE,GAAG,EAAE,GAAE,CAAC;IACrB,SAAS,EAAE,GAAG,EAAE,GAAE,CAAC;CACpB,CAAA;AAED,SAAS,IAAI,CAAC,OAAe;IAC3B,MAAM,IAAI,KAAK,CAAC,sBAAsB,OAAO,EAAE,CAAC,CAAA;AAClD,CAAC;AAED,SAAS,WAAW,CAAC,MAAiB,EAAE,EAAU,EAAE,GAAW;IAC7D,IAAI,GAAG,KAAK,IAAI;QACd,OAAO,IAAI,CAAA;IACb,OAAO,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,CAAA;AACnD,CAAC;AAED,SAAS,eAAe,CAAC,MAAiB,EAAE,EAAU,EAAE,GAAW;IACjE,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,GAAG,CAAC,CAAC,CAAA;AAClE,CAAC;AAED,0EAA0E;AAC1E,SAAS,QAAQ,CAAC,MAAiB,EAAE,EAAU,EAAE,IAAY;IAC3D,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC7B,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,EAAE,CAAA;IAC5B,IAAI,QAAQ,KAAK,SAAS;QACxB,OAAO,KAAK,CAAA;IACd,IAAI,OAAO,GAAG,EAAE,CAAA;IAChB,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,CAAC;QAC1B,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,EAAE,UAAU,CAAA;QACnE,IAAI,CAAC,MAAM;YACT,OAAO,KAAK,CAAA;QACd,OAAO,GAAG,MAAM,CAAA;IAClB,CAAC;IACD,OAAO,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAA;AAC/C,CAAC;AAED,8CAA8C;AAC9C,SAAgB,eAAe,CAAC,MAAiB,EAAE,EAAU;IAC3D,OAAO,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAA;AACrC,CAAC;AAED;;;;GAIG;AACH,SAAgB,aAAa,CAC3B,MAAiB,EACjB,EAAU,EACV,UAAmB;IAEnB,OAAO;QACL,KAAK,EAAE,GAAG,CAAC,EAAE,CAAC,WAAW,CAAC,MAAM,EAAE,EAAE,EAAE,GAAG,CAAC;eACrC,IAAI,CAAC,IAAI,GAAG,wBAAwB,EAAE,GAAG,CAAC;QAC/C,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,EAAE,IAAI,CAAC;eAClC,IAAI,CAAC,IAAI,IAAI,mCAAmC,EAAE,GAAG,CAAC;QAC3D,SAAS,EAAE,GAAG,CAAC,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE,EAAE,EAAE,GAAG,CAAC;eAC7C,IAAI,CAAC,IAAI,GAAG,qCAAqC,EAAE,GAAG,CAAC;QAC5D,OAAO,EAAE,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;eACrE,IAAI,CAAC,IAAI,IAAI,gCAAgC,CAAC;QACnD,WAAW,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,UAAU,IAAI,WAAW,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;eACnE,IAAI,CAAC,IAAI,GAAG,yCAAyC,UAAU,GAAG,CAAC;QACxE,SAAS,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,UAAU,IAAI,QAAQ,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;eAChE,IAAI,CAAC,IAAI,IAAI,oDAAoD,UAAU,GAAG,CAAC;KACrF,CAAA;AACH,CAAC","sourcesContent":["/**\n * Runtime schema validation — the dev-time assertions `definePerms(schema)`\n * adds on top of the type layer. The types are the primary safety net\n * (principle 3); these catch the cases a dynamically-built rules object can\n * smuggle past the compiler, and turn a silent bad-CEL push into a clear throw\n * at author time.\n *\n * When no schema value is passed (`definePerms()` / `definePerms<S>()`), every\n * check is a no-op — there is nothing to validate against.\n */\nimport type { IdbSchema } from '../schema/defineSchema.js'\n\n/** The per-callback validation hooks the context wires into its helpers. */\nexport interface Validator {\n field: (key: string) => void\n ref: (path: string) => void\n ruleParam: (key: string) => void\n authRef: (path: string) => void\n linkedField: (key: string) => void\n linkedRef: (path: string) => void\n}\n\n/** The inert validator — used in type-only mode. */\nexport const noValidate: Validator = {\n field: () => {},\n ref: () => {},\n ruleParam: () => {},\n authRef: () => {},\n linkedField: () => {},\n linkedRef: () => {},\n}\n\nfunction fail(message: string): never {\n throw new Error(`QERR_PERMS_SCHEMA: ${message}`)\n}\n\nfunction fieldExists(schema: IdbSchema, ns: string, key: string): boolean {\n if (key === 'id')\n return true\n return Boolean(schema.entities[ns]?.attrs?.[key])\n}\n\nfunction ruleParamExists(schema: IdbSchema, ns: string, key: string): boolean {\n return Boolean(schema.$dux?.namespaces?.[ns]?.ruleParams?.[key])\n}\n\n/** Walk a `link(.link)*.attr` path; the terminal must be an attribute. */\nfunction refValid(schema: IdbSchema, ns: string, path: string): boolean {\n const parts = path.split('.')\n const terminal = parts.pop()\n if (terminal === undefined)\n return false\n let current = ns\n for (const label of parts) {\n const target = schema.entities[current]?.links?.[label]?.entityName\n if (!target)\n return false\n current = target\n }\n return fieldExists(schema, current, terminal)\n}\n\n/** Does the schema declare this namespace? */\nexport function namespaceExists(schema: IdbSchema, ns: string): boolean {\n return Boolean(schema.entities[ns])\n}\n\n/**\n * Build the validator for a namespace callback. `linkTarget` is set only when\n * resolving a specific link/unlink rule, so `el`/`elr` validate against the\n * linked namespace.\n */\nexport function makeValidator(\n schema: IdbSchema,\n ns: string,\n linkTarget?: string,\n): Validator {\n return {\n field: key => fieldExists(schema, ns, key)\n || fail(`'${key}' is not a field on '${ns}'`),\n ref: path => refValid(schema, ns, path)\n || fail(`'${path}' is not a valid ref path from '${ns}'`),\n ruleParam: key => ruleParamExists(schema, ns, key)\n || fail(`'${key}' is not a declared ruleParam on '${ns}'`),\n authRef: path => refValid(schema, '$users', path.replace(/^\\$user\\./, ''))\n || fail(`'${path}' is not a valid auth ref path`),\n linkedField: key => (linkTarget && fieldExists(schema, linkTarget, key))\n || fail(`'${key}' is not a field on linked namespace '${linkTarget}'`),\n linkedRef: path => (linkTarget && refValid(schema, linkTarget, path))\n || fail(`'${path}' is not a valid ref path from linked namespace '${linkTarget}'`),\n }\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `$only` is a `true` constant sharing its name with the `$:` key it enables,
|
|
3
|
+
* so property shorthand reads as the declaration it is:
|
|
4
|
+
* `$: { where: { id }, $only }` ≡ `$: { where: { id }, $only: true }`.
|
|
5
|
+
*/
|
|
6
|
+
export declare const $only: true;
|
|
7
|
+
/**
|
|
8
|
+
* `$skip` is an `undefined` constant: an `undefined` value in a `where`
|
|
9
|
+
* clause drops that clause before the query goes on the wire, so
|
|
10
|
+
* `where: { workspace: current?.id ?? $skip }` reads as intended.
|
|
11
|
+
*/
|
|
12
|
+
export declare const $skip: undefined;
|
|
13
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/query/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,KAAK,EAAG,IAAa,CAAA;AAElC;;;;GAIG;AACH,eAAO,MAAM,KAAK,WAAY,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.$skip = exports.$only = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* `$only` is a `true` constant sharing its name with the `$:` key it enables,
|
|
6
|
+
* so property shorthand reads as the declaration it is:
|
|
7
|
+
* `$: { where: { id }, $only }` ≡ `$: { where: { id }, $only: true }`.
|
|
8
|
+
*/
|
|
9
|
+
exports.$only = true;
|
|
10
|
+
/**
|
|
11
|
+
* `$skip` is an `undefined` constant: an `undefined` value in a `where`
|
|
12
|
+
* clause drops that clause before the query goes on the wire, so
|
|
13
|
+
* `where: { workspace: current?.id ?? $skip }` reads as intended.
|
|
14
|
+
*/
|
|
15
|
+
exports.$skip = undefined;
|
|
16
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/query/constants.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACU,QAAA,KAAK,GAAG,IAAa,CAAA;AAElC;;;;GAIG;AACU,QAAA,KAAK,GAAG,SAAS,CAAA","sourcesContent":["/**\n * `$only` is a `true` constant sharing its name with the `$:` key it enables,\n * so property shorthand reads as the declaration it is:\n * `$: { where: { id }, $only }` ≡ `$: { where: { id }, $only: true }`.\n */\nexport const $only = true as const\n\n/**\n * `$skip` is an `undefined` constant: an `undefined` value in a `where`\n * clause drops that clause before the query goes on the wire, so\n * `where: { workspace: current?.id ?? $skip }` reads as intended.\n */\nexport const $skip = undefined\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { IdbSchema } from '../schema/defineSchema.js';
|
|
2
|
+
import type { IdbRegisteredSchema } from '../schema/register.js';
|
|
3
|
+
import type { IdbValidQuery } from './validation.js';
|
|
4
|
+
/**
|
|
5
|
+
* A schema-bound `q`: validates the query and returns it, type intact.
|
|
6
|
+
* The `const` type parameter keeps `$only: true`, `$as` names, and `indexBy`
|
|
7
|
+
* keys literal — the shaping mirror depends on them.
|
|
8
|
+
*/
|
|
9
|
+
export interface IdbQueryBuilder<S extends IdbSchema> {
|
|
10
|
+
<const Q extends IdbValidQuery<Q, S>>(query: Q): Q;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The multi-schema escape hatch: a `q` bound to an explicit schema type.
|
|
14
|
+
* The runtime is schema-independent — all validation is type-level.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* const oq = defineQuery<OtherSchema>()
|
|
18
|
+
* const query = oq({ posts: {} })
|
|
19
|
+
*/
|
|
20
|
+
export declare function defineQuery<S extends IdbSchema = IdbRegisteredSchema>(): IdbQueryBuilder<S>;
|
|
21
|
+
/**
|
|
22
|
+
* Schema-aware query authoring, ready-made via registration. Wrap a query in
|
|
23
|
+
* `q()` to get completions and field-localized errors anywhere — inline,
|
|
24
|
+
* named and shared, or inside a factory body:
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* const { tasks } = db.useQuery(() => {
|
|
28
|
+
* if (!userId) return null
|
|
29
|
+
* return q({ tasks: { $: { where: { isDone: false } } } })
|
|
30
|
+
* })
|
|
31
|
+
*/
|
|
32
|
+
export declare const q: IdbQueryBuilder<IdbRegisteredSchema>;
|
|
33
|
+
//# sourceMappingURL=defineQuery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineQuery.d.ts","sourceRoot":"","sources":["../../../src/query/defineQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAC1D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAChE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAEpD;;;;GAIG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,SAAS;IAClD,CAAC,KAAK,CAAC,CAAC,SAAS,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAAA;CACnD;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,SAAS,GAAG,mBAAmB,KAAK,eAAe,CAAC,CAAC,CAAC,CAE3F;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,CAAC,EAAE,eAAe,CAAC,mBAAmB,CAAiC,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.q = void 0;
|
|
4
|
+
exports.defineQuery = defineQuery;
|
|
5
|
+
/**
|
|
6
|
+
* The multi-schema escape hatch: a `q` bound to an explicit schema type.
|
|
7
|
+
* The runtime is schema-independent — all validation is type-level.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const oq = defineQuery<OtherSchema>()
|
|
11
|
+
* const query = oq({ posts: {} })
|
|
12
|
+
*/
|
|
13
|
+
function defineQuery() {
|
|
14
|
+
return query => query;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Schema-aware query authoring, ready-made via registration. Wrap a query in
|
|
18
|
+
* `q()` to get completions and field-localized errors anywhere — inline,
|
|
19
|
+
* named and shared, or inside a factory body:
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const { tasks } = db.useQuery(() => {
|
|
23
|
+
* if (!userId) return null
|
|
24
|
+
* return q({ tasks: { $: { where: { isDone: false } } } })
|
|
25
|
+
* })
|
|
26
|
+
*/
|
|
27
|
+
exports.q = defineQuery();
|
|
28
|
+
//# sourceMappingURL=defineQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineQuery.js","sourceRoot":"","sources":["../../../src/query/defineQuery.ts"],"names":[],"mappings":";;;AAqBA,kCAEC;AAVD;;;;;;;GAOG;AACH,SAAgB,WAAW;IACzB,OAAO,KAAK,CAAC,EAAE,CAAC,KAAK,CAAA;AACvB,CAAC;AAED;;;;;;;;;;GAUG;AACU,QAAA,CAAC,GAAyD,WAAW,EAAE,CAAA","sourcesContent":["import type { IdbSchema } from '../schema/defineSchema.js'\nimport type { IdbRegisteredSchema } from '../schema/register.js'\nimport type { IdbValidQuery } from './validation.js'\n\n/**\n * A schema-bound `q`: validates the query and returns it, type intact.\n * The `const` type parameter keeps `$only: true`, `$as` names, and `indexBy`\n * keys literal — the shaping mirror depends on them.\n */\nexport interface IdbQueryBuilder<S extends IdbSchema> {\n <const Q extends IdbValidQuery<Q, S>>(query: Q): Q\n}\n\n/**\n * The multi-schema escape hatch: a `q` bound to an explicit schema type.\n * The runtime is schema-independent — all validation is type-level.\n *\n * @example\n * const oq = defineQuery<OtherSchema>()\n * const query = oq({ posts: {} })\n */\nexport function defineQuery<S extends IdbSchema = IdbRegisteredSchema>(): IdbQueryBuilder<S> {\n return query => query\n}\n\n/**\n * Schema-aware query authoring, ready-made via registration. Wrap a query in\n * `q()` to get completions and field-localized errors anywhere — inline,\n * named and shared, or inside a factory body:\n *\n * @example\n * const { tasks } = db.useQuery(() => {\n * if (!userId) return null\n * return q({ tasks: { $: { where: { isDone: false } } } })\n * })\n */\nexport const q: IdbQueryBuilder<IdbRegisteredSchema> = /* @__PURE__ */ defineQuery()\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { $only, $skip } from './constants.js';
|
|
2
|
+
export type { IdbQueryBuilder } from './defineQuery.js';
|
|
3
|
+
export { defineQuery, q } from './defineQuery.js';
|
|
4
|
+
export type { HasPick, ResolvedScopeKey, SingularScopeKey } from './keys.js';
|
|
5
|
+
export { resultKeys, shapeResult, shapingSchema } from './shapeResult.js';
|
|
6
|
+
export type { IdbMBlock, IdbMTransform, IdbQuery, IdbQueryData, IdbQueryEntity, IdbQueryFields, IdbQueryNode, IdbQueryOptions, IdbQueryPageInfo, IdbQuerySubquery, IdbSchemaRuleParams, IdbWhereOps, } from './types.js';
|
|
7
|
+
export type { IdbValidQuery } from './validation.js';
|
|
8
|
+
export { toWireQuery } from './wire.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/query/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAC7C,YAAY,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,kBAAkB,CAAA;AACjD,YAAY,EAAE,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA;AAC5E,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AACzE,YAAY,EACV,SAAS,EACT,aAAa,EACb,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,cAAc,EACd,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,WAAW,GACZ,MAAM,YAAY,CAAA;AACnB,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toWireQuery = exports.shapingSchema = exports.shapeResult = exports.resultKeys = exports.q = exports.defineQuery = exports.$skip = exports.$only = void 0;
|
|
4
|
+
var constants_js_1 = require("./constants.js");
|
|
5
|
+
Object.defineProperty(exports, "$only", { enumerable: true, get: function () { return constants_js_1.$only; } });
|
|
6
|
+
Object.defineProperty(exports, "$skip", { enumerable: true, get: function () { return constants_js_1.$skip; } });
|
|
7
|
+
var defineQuery_js_1 = require("./defineQuery.js");
|
|
8
|
+
Object.defineProperty(exports, "defineQuery", { enumerable: true, get: function () { return defineQuery_js_1.defineQuery; } });
|
|
9
|
+
Object.defineProperty(exports, "q", { enumerable: true, get: function () { return defineQuery_js_1.q; } });
|
|
10
|
+
var shapeResult_js_1 = require("./shapeResult.js");
|
|
11
|
+
Object.defineProperty(exports, "resultKeys", { enumerable: true, get: function () { return shapeResult_js_1.resultKeys; } });
|
|
12
|
+
Object.defineProperty(exports, "shapeResult", { enumerable: true, get: function () { return shapeResult_js_1.shapeResult; } });
|
|
13
|
+
Object.defineProperty(exports, "shapingSchema", { enumerable: true, get: function () { return shapeResult_js_1.shapingSchema; } });
|
|
14
|
+
var wire_js_1 = require("./wire.js");
|
|
15
|
+
Object.defineProperty(exports, "toWireQuery", { enumerable: true, get: function () { return wire_js_1.toWireQuery; } });
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/query/index.ts"],"names":[],"mappings":";;;AAAA,+CAA6C;AAApC,qGAAA,KAAK,OAAA;AAAE,qGAAA,KAAK,OAAA;AAErB,mDAAiD;AAAxC,6GAAA,WAAW,OAAA;AAAE,mGAAA,CAAC,OAAA;AAEvB,mDAAyE;AAAhE,4GAAA,UAAU,OAAA;AAAE,6GAAA,WAAW,OAAA;AAAE,+GAAA,aAAa,OAAA;AAgB/C,qCAAuC;AAA9B,sGAAA,WAAW,OAAA","sourcesContent":["export { $only, $skip } from './constants.js'\nexport type { IdbQueryBuilder } from './defineQuery.js'\nexport { defineQuery, q } from './defineQuery.js'\nexport type { HasPick, ResolvedScopeKey, SingularScopeKey } from './keys.js'\nexport { resultKeys, shapeResult, shapingSchema } from './shapeResult.js'\nexport type {\n IdbMBlock,\n IdbMTransform,\n IdbQuery,\n IdbQueryData,\n IdbQueryEntity,\n IdbQueryFields,\n IdbQueryNode,\n IdbQueryOptions,\n IdbQueryPageInfo,\n IdbQuerySubquery,\n IdbSchemaRuleParams,\n IdbWhereOps,\n} from './types.js'\nexport type { IdbValidQuery } from './validation.js'\nexport { toWireQuery } from './wire.js'\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-level scope-key resolution — the mirror of `resolveSingularKey` in
|
|
3
|
+
* `shapeResult.ts`. Both derive from the same schema metadata, so the
|
|
4
|
+
* TypeScript key and the runtime key always match.
|
|
5
|
+
*
|
|
6
|
+
* `ParentNS` is `null` for top-level scopes (the key is a namespace name) and
|
|
7
|
+
* the parent's namespace name for nested scopes (the key is a link label).
|
|
8
|
+
*/
|
|
9
|
+
import type { IdbSchema } from '../schema/defineSchema.js';
|
|
10
|
+
import type { Singularize } from '../schema/singularize.js';
|
|
11
|
+
type DeclaredSingular<S extends IdbSchema, ParentNS extends string | null, Key extends string> = ParentNS extends null ? Key extends keyof S['$dux']['namespaces'] ? S['$dux']['namespaces'][Key]['singular'] : undefined : ParentNS extends keyof S['$dux']['linkSingulars'] ? Key extends keyof S['$dux']['linkSingulars'][ParentNS] ? S['$dux']['linkSingulars'][ParentNS][Key] : undefined : undefined;
|
|
12
|
+
/** The singular form of a scope key per the schema's `options.singularize`. */
|
|
13
|
+
export type SingularScopeKey<S extends IdbSchema, ParentNS extends string | null, Key extends string> = S['$dux']['options']['singularize'] extends 'off' ? Key : DeclaredSingular<S, ParentNS, Key> extends infer Declared ? Declared extends string ? Declared : S['$dux']['options']['singularize'] extends 'explicit' ? Key : Singularize<Key> : never;
|
|
14
|
+
/** Whether a scope node coerces its array to a single entity. */
|
|
15
|
+
export type HasPick<Node> = Node extends {
|
|
16
|
+
$: infer Dollar;
|
|
17
|
+
} ? Dollar extends {
|
|
18
|
+
$only: true;
|
|
19
|
+
} | {
|
|
20
|
+
$at: number;
|
|
21
|
+
} ? true : false : false;
|
|
22
|
+
/** The output key of a scope: `$as` wins, `$only`/`$at` singularize, else as-is. */
|
|
23
|
+
export type ResolvedScopeKey<S extends IdbSchema, ParentNS extends string | null, Key extends string, Node> = Node extends {
|
|
24
|
+
$: infer Dollar;
|
|
25
|
+
} ? Dollar extends {
|
|
26
|
+
$as: infer As extends string;
|
|
27
|
+
} ? As : Dollar extends {
|
|
28
|
+
$only: true;
|
|
29
|
+
} | {
|
|
30
|
+
$at: number;
|
|
31
|
+
} ? SingularScopeKey<S, ParentNS, Key> : Key : Key;
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=keys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../../src/query/keys.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAE3D,KAAK,gBAAgB,CACnB,CAAC,SAAS,SAAS,EACnB,QAAQ,SAAS,MAAM,GAAG,IAAI,EAC9B,GAAG,SAAS,MAAM,IAChB,QAAQ,SAAS,IAAI,GACrB,GAAG,SAAS,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,GACvC,CAAC,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,GACxC,SAAS,GACX,QAAQ,SAAS,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,GAC/C,GAAG,SAAS,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,CAAC,QAAQ,CAAC,GACpD,CAAC,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,GACzC,SAAS,GACX,SAAS,CAAA;AAEf,+EAA+E;AAC/E,MAAM,MAAM,gBAAgB,CAC1B,CAAC,SAAS,SAAS,EACnB,QAAQ,SAAS,MAAM,GAAG,IAAI,EAC9B,GAAG,SAAS,MAAM,IAChB,CAAC,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,aAAa,CAAC,SAAS,KAAK,GACjD,GAAG,GACH,gBAAgB,CAAC,CAAC,EAAE,QAAQ,EAAE,GAAG,CAAC,SAAS,MAAM,QAAQ,GACvD,QAAQ,SAAS,MAAM,GACrB,QAAQ,GACR,CAAC,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,aAAa,CAAC,SAAS,UAAU,GACpD,GAAG,GACH,WAAW,CAAC,GAAG,CAAC,GACpB,KAAK,CAAA;AAEX,iEAAiE;AACjE,MAAM,MAAM,OAAO,CAAC,IAAI,IAAI,IAAI,SAAS;IAAE,CAAC,EAAE,MAAM,MAAM,CAAA;CAAE,GACxD,MAAM,SAAS;IAAE,KAAK,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,GAC9C,IAAI,GACJ,KAAK,GACP,KAAK,CAAA;AAET,oFAAoF;AACpF,MAAM,MAAM,gBAAgB,CAC1B,CAAC,SAAS,SAAS,EACnB,QAAQ,SAAS,MAAM,GAAG,IAAI,EAC9B,GAAG,SAAS,MAAM,EAClB,IAAI,IACF,IAAI,SAAS;IAAE,CAAC,EAAE,MAAM,MAAM,CAAA;CAAE,GAChC,MAAM,SAAS;IAAE,GAAG,EAAE,MAAM,EAAE,SAAS,MAAM,CAAA;CAAE,GAC7C,EAAE,GACF,MAAM,SAAS;IAAE,KAAK,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,GAC9C,gBAAgB,CAAC,CAAC,EAAE,QAAQ,EAAE,GAAG,CAAC,GAClC,GAAG,GACP,GAAG,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../../../src/query/keys.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Type-level scope-key resolution — the mirror of `resolveSingularKey` in\n * `shapeResult.ts`. Both derive from the same schema metadata, so the\n * TypeScript key and the runtime key always match.\n *\n * `ParentNS` is `null` for top-level scopes (the key is a namespace name) and\n * the parent's namespace name for nested scopes (the key is a link label).\n */\nimport type { IdbSchema } from '../schema/defineSchema.js'\nimport type { Singularize } from '../schema/singularize.js'\n\ntype DeclaredSingular<\n S extends IdbSchema,\n ParentNS extends string | null,\n Key extends string,\n> = ParentNS extends null\n ? Key extends keyof S['$dux']['namespaces']\n ? S['$dux']['namespaces'][Key]['singular']\n : undefined\n : ParentNS extends keyof S['$dux']['linkSingulars']\n ? Key extends keyof S['$dux']['linkSingulars'][ParentNS]\n ? S['$dux']['linkSingulars'][ParentNS][Key]\n : undefined\n : undefined\n\n/** The singular form of a scope key per the schema's `options.singularize`. */\nexport type SingularScopeKey<\n S extends IdbSchema,\n ParentNS extends string | null,\n Key extends string,\n> = S['$dux']['options']['singularize'] extends 'off'\n ? Key\n : DeclaredSingular<S, ParentNS, Key> extends infer Declared\n ? Declared extends string\n ? Declared\n : S['$dux']['options']['singularize'] extends 'explicit'\n ? Key\n : Singularize<Key>\n : never\n\n/** Whether a scope node coerces its array to a single entity. */\nexport type HasPick<Node> = Node extends { $: infer Dollar }\n ? Dollar extends { $only: true } | { $at: number }\n ? true\n : false\n : false\n\n/** The output key of a scope: `$as` wins, `$only`/`$at` singularize, else as-is. */\nexport type ResolvedScopeKey<\n S extends IdbSchema,\n ParentNS extends string | null,\n Key extends string,\n Node,\n> = Node extends { $: infer Dollar }\n ? Dollar extends { $as: infer As extends string }\n ? As\n : Dollar extends { $only: true } | { $at: number }\n ? SingularScopeKey<S, ParentNS, Key>\n : Key\n : Key\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one place result-shaping logic exists. `/vue` wraps it reactively,
|
|
3
|
+
* `/admin` applies it post-`await` — both deliver identical shapes for the
|
|
4
|
+
* same query by construction. The type-level mirror is `IdbQueryData`
|
|
5
|
+
* (`types.ts`); the two derive from the same schema source so the runtime key
|
|
6
|
+
* and the TypeScript key always match.
|
|
7
|
+
*
|
|
8
|
+
* Shaping per scope:
|
|
9
|
+
* - top-level namespaces normalize to `Entity[]` — never `undefined`
|
|
10
|
+
* - `$only` picks element 0, `$at: n` picks position n (negative from the
|
|
11
|
+
* end); both rename the scope key to its singular form per the schema
|
|
12
|
+
* - `$as` renames explicitly and always wins
|
|
13
|
+
* - `$m` adds labeled sibling keys (`indexBy` / `groupBy` / `at`) computed in
|
|
14
|
+
* a single pass over the scope's data, leaving the original key untouched
|
|
15
|
+
* - nested link scopes shape recursively inside each entity; untouched
|
|
16
|
+
* subtrees are returned by reference, never copied
|
|
17
|
+
*/
|
|
18
|
+
import type { IdbSchema } from '../schema/defineSchema.js';
|
|
19
|
+
type AnyRecord = Record<string, any>;
|
|
20
|
+
/**
|
|
21
|
+
* The top-level keys a shaped result will carry for a query — the resolved
|
|
22
|
+
* scope keys plus every `$m` sibling label — derived from the query structure
|
|
23
|
+
* alone, no data needed. The client overlay uses this to expose one reactive
|
|
24
|
+
* ref per scope for destructuring.
|
|
25
|
+
*/
|
|
26
|
+
export declare function resultKeys(query: AnyRecord, schema: IdbSchema): string[];
|
|
27
|
+
/**
|
|
28
|
+
* A schema with a usable `$dux` projection for runtime shaping — the real
|
|
29
|
+
* schema when one is registered, a permissive stub otherwise (singularize
|
|
30
|
+
* 'auto', no declared singulars, no link metadata). Both clients reach for it
|
|
31
|
+
* so a query with no schema still shapes consistently.
|
|
32
|
+
*/
|
|
33
|
+
export declare function shapingSchema(schema: IdbSchema | undefined): IdbSchema;
|
|
34
|
+
export declare function shapeResult(rawData: AnyRecord | undefined, query: AnyRecord, schema: IdbSchema): AnyRecord;
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=shapeResult.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shapeResult.d.ts","sourceRoot":"","sources":["../../../src/query/shapeResult.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAG1D,KAAK,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAQpC;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,GAAG,MAAM,EAAE,CAmBxE;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAStE;AAED,wBAAgB,WAAW,CACzB,OAAO,EAAE,SAAS,GAAG,SAAS,EAC9B,KAAK,EAAE,SAAS,EAChB,MAAM,EAAE,SAAS,GAChB,SAAS,CAUX"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The one place result-shaping logic exists. `/vue` wraps it reactively,
|
|
4
|
+
* `/admin` applies it post-`await` — both deliver identical shapes for the
|
|
5
|
+
* same query by construction. The type-level mirror is `IdbQueryData`
|
|
6
|
+
* (`types.ts`); the two derive from the same schema source so the runtime key
|
|
7
|
+
* and the TypeScript key always match.
|
|
8
|
+
*
|
|
9
|
+
* Shaping per scope:
|
|
10
|
+
* - top-level namespaces normalize to `Entity[]` — never `undefined`
|
|
11
|
+
* - `$only` picks element 0, `$at: n` picks position n (negative from the
|
|
12
|
+
* end); both rename the scope key to its singular form per the schema
|
|
13
|
+
* - `$as` renames explicitly and always wins
|
|
14
|
+
* - `$m` adds labeled sibling keys (`indexBy` / `groupBy` / `at`) computed in
|
|
15
|
+
* a single pass over the scope's data, leaving the original key untouched
|
|
16
|
+
* - nested link scopes shape recursively inside each entity; untouched
|
|
17
|
+
* subtrees are returned by reference, never copied
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.resultKeys = resultKeys;
|
|
21
|
+
exports.shapingSchema = shapingSchema;
|
|
22
|
+
exports.shapeResult = shapeResult;
|
|
23
|
+
const singularize_js_1 = require("../schema/singularize.js");
|
|
24
|
+
/**
|
|
25
|
+
* The top-level keys a shaped result will carry for a query — the resolved
|
|
26
|
+
* scope keys plus every `$m` sibling label — derived from the query structure
|
|
27
|
+
* alone, no data needed. The client overlay uses this to expose one reactive
|
|
28
|
+
* ref per scope for destructuring.
|
|
29
|
+
*/
|
|
30
|
+
function resultKeys(query, schema) {
|
|
31
|
+
const keys = [];
|
|
32
|
+
for (const [key, node] of Object.entries(query)) {
|
|
33
|
+
if (key === '$$ruleParams')
|
|
34
|
+
continue;
|
|
35
|
+
const dollar = node?.$ ?? {};
|
|
36
|
+
const pick = dollar.$only === true || typeof dollar.$at === 'number';
|
|
37
|
+
keys.push(typeof dollar.$as === 'string'
|
|
38
|
+
? dollar.$as
|
|
39
|
+
: pick
|
|
40
|
+
? resolveSingularKey(key, null, schema)
|
|
41
|
+
: key);
|
|
42
|
+
const m = node?.$m;
|
|
43
|
+
if (m)
|
|
44
|
+
keys.push(...Object.keys(m));
|
|
45
|
+
}
|
|
46
|
+
return keys;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A schema with a usable `$dux` projection for runtime shaping — the real
|
|
50
|
+
* schema when one is registered, a permissive stub otherwise (singularize
|
|
51
|
+
* 'auto', no declared singulars, no link metadata). Both clients reach for it
|
|
52
|
+
* so a query with no schema still shapes consistently.
|
|
53
|
+
*/
|
|
54
|
+
function shapingSchema(schema) {
|
|
55
|
+
if (schema)
|
|
56
|
+
return schema;
|
|
57
|
+
return {
|
|
58
|
+
entities: {},
|
|
59
|
+
links: {},
|
|
60
|
+
rooms: {},
|
|
61
|
+
$dux: { namespaces: {}, linkSingulars: {}, options: { singularize: 'auto' } },
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function shapeResult(rawData, query, schema) {
|
|
65
|
+
const out = {};
|
|
66
|
+
for (const [key, node] of Object.entries(query)) {
|
|
67
|
+
// `$`-prefixed namespaces ($users, …) are data; only the internal
|
|
68
|
+
// ruleParams envelope is not a scope.
|
|
69
|
+
if (key === '$$ruleParams')
|
|
70
|
+
continue;
|
|
71
|
+
shapeScopeInto(out, rawData?.[key] ?? [], key, node ?? {}, null, key, schema);
|
|
72
|
+
}
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Shapes one scope into `out`: the resolved scope key, plus any `$m` sibling
|
|
77
|
+
* keys. `parentNs` is the namespace the scope key sits on (`null` for
|
|
78
|
+
* top-level scopes); `ns` is the namespace the scope's entities belong to.
|
|
79
|
+
*/
|
|
80
|
+
function shapeScopeInto(out, raw, key, node, parentNs, ns, schema) {
|
|
81
|
+
const dollar = node.$ ?? {};
|
|
82
|
+
const value = shapeChildren(raw, node, ns, schema);
|
|
83
|
+
if (node.$m && Array.isArray(value))
|
|
84
|
+
applyMSiblings(out, value, node.$m);
|
|
85
|
+
const pick = dollar.$only === true ? 0 : typeof dollar.$at === 'number' ? dollar.$at : null;
|
|
86
|
+
const picked = pick !== null && Array.isArray(value) ? value.at(pick) : value;
|
|
87
|
+
const outputKey = typeof dollar.$as === 'string'
|
|
88
|
+
? dollar.$as
|
|
89
|
+
: pick !== null
|
|
90
|
+
? resolveSingularKey(key, parentNs, schema)
|
|
91
|
+
: key;
|
|
92
|
+
out[outputKey] = picked;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Recursively shapes the nested link scopes inside each entity of a scope
|
|
96
|
+
* whose entities belong to `ns`. Entities are copied only along paths that
|
|
97
|
+
* actually change.
|
|
98
|
+
*/
|
|
99
|
+
function shapeChildren(raw, node, ns, schema) {
|
|
100
|
+
const childKeys = Object.keys(node).filter(k => k !== '$' && k !== '$m');
|
|
101
|
+
if (childKeys.length === 0 || !childKeys.some(k => subtreeReshapes(node[k])))
|
|
102
|
+
return raw;
|
|
103
|
+
const shapeEntity = (entity) => {
|
|
104
|
+
if (entity === null || typeof entity !== 'object')
|
|
105
|
+
return entity;
|
|
106
|
+
const copy = { ...entity };
|
|
107
|
+
for (const childKey of childKeys) {
|
|
108
|
+
const childRaw = copy[childKey];
|
|
109
|
+
delete copy[childKey];
|
|
110
|
+
const childNs = linkTarget(schema, ns, childKey);
|
|
111
|
+
shapeScopeInto(copy, childRaw, childKey, node[childKey] ?? {}, ns, childNs, schema);
|
|
112
|
+
}
|
|
113
|
+
return copy;
|
|
114
|
+
};
|
|
115
|
+
return Array.isArray(raw) ? raw.map(shapeEntity) : shapeEntity(raw);
|
|
116
|
+
}
|
|
117
|
+
/** The namespace a link label on `ns` points to, via the enriched entity defs. */
|
|
118
|
+
function linkTarget(schema, ns, label) {
|
|
119
|
+
return schema.entities[ns]?.links?.[label]?.entityName ?? label;
|
|
120
|
+
}
|
|
121
|
+
/** Whether a subtree contains any directive that changes the data shape. */
|
|
122
|
+
function subtreeReshapes(node) {
|
|
123
|
+
if (node === null || typeof node !== 'object')
|
|
124
|
+
return false;
|
|
125
|
+
const record = node;
|
|
126
|
+
if (record.$m !== undefined)
|
|
127
|
+
return true;
|
|
128
|
+
const dollar = record.$;
|
|
129
|
+
if (dollar && (dollar.$only !== undefined || dollar.$at !== undefined || dollar.$as !== undefined))
|
|
130
|
+
return true;
|
|
131
|
+
return Object.keys(record).some(k => k !== '$' && k !== '$m' && subtreeReshapes(record[k]));
|
|
132
|
+
}
|
|
133
|
+
/** All `$m` projections for one scope, computed in a single pass. */
|
|
134
|
+
function applyMSiblings(out, entities, transforms) {
|
|
135
|
+
const labels = Object.entries(transforms);
|
|
136
|
+
for (const [label, transform] of labels) {
|
|
137
|
+
out[label] = typeof transform.at === 'number'
|
|
138
|
+
? entities.at(transform.at)
|
|
139
|
+
: {};
|
|
140
|
+
}
|
|
141
|
+
for (const entity of entities) {
|
|
142
|
+
for (const [label, transform] of labels) {
|
|
143
|
+
if (transform.indexBy !== undefined) {
|
|
144
|
+
const indexValue = entity[transform.indexBy];
|
|
145
|
+
if (indexValue !== null && indexValue !== undefined)
|
|
146
|
+
out[label][String(indexValue)] = entity;
|
|
147
|
+
}
|
|
148
|
+
else if (transform.groupBy !== undefined) {
|
|
149
|
+
const groupValue = entity[transform.groupBy];
|
|
150
|
+
if (groupValue !== null && groupValue !== undefined)
|
|
151
|
+
(out[label][String(groupValue)] ??= []).push(entity);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* The singular form of a scope key — declared `singular` first (namespace
|
|
158
|
+
* `singular` for top-level keys, link label `singular` for nested keys), the
|
|
159
|
+
* shared algorithm as the `'auto'` fallback, honoring `options.singularize`.
|
|
160
|
+
*/
|
|
161
|
+
function resolveSingularKey(key, parentNs, schema) {
|
|
162
|
+
const meta = schema.$dux;
|
|
163
|
+
const mode = meta.options.singularize;
|
|
164
|
+
if (mode === 'off')
|
|
165
|
+
return key;
|
|
166
|
+
const declared = parentNs === null
|
|
167
|
+
? meta.namespaces[key]?.singular
|
|
168
|
+
: meta.linkSingulars[parentNs]?.[key];
|
|
169
|
+
if (declared !== undefined)
|
|
170
|
+
return declared;
|
|
171
|
+
return mode === 'auto' ? (0, singularize_js_1.singularize)(key) : key;
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=shapeResult.js.map
|