@primate/core 0.4.6 → 0.6.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/lib/private/App.d.ts +771 -6
- package/lib/private/App.js +49 -16
- package/lib/private/Binder.d.ts +2 -2
- package/lib/private/Flags.d.ts +8 -4
- package/lib/private/Module.d.ts +4 -16
- package/lib/private/Module.js +1 -17
- package/lib/private/app/EnvSchema.d.ts +5 -0
- package/lib/private/app/EnvSchema.js +2 -0
- package/lib/private/app/Facade.browser.d.ts +11 -0
- package/lib/private/app/Facade.browser.js +19 -0
- package/lib/private/app/Facade.d.ts +811 -0
- package/lib/private/app/Facade.js +56 -0
- package/lib/private/asset/Asset.d.ts +1 -1
- package/lib/private/build/App.d.ts +2 -2
- package/lib/private/build/App.js +0 -2
- package/lib/private/build/client/index.js +19 -10
- package/lib/private/build/client/plugin/app-request.d.ts +4 -0
- package/lib/private/build/client/plugin/app-request.js +19 -0
- package/lib/private/build/client/plugin/view.d.ts +4 -0
- package/lib/private/build/client/plugin/view.js +13 -0
- package/lib/private/build/hook.d.ts +1 -2
- package/lib/private/build/hook.js +25 -19
- package/lib/private/build/index.d.ts +2 -1
- package/lib/private/build/index.js +27 -27
- package/lib/private/build/presets.d.ts +10 -0
- package/lib/private/build/presets.js +39 -0
- package/lib/private/build/server/index.js +10 -14
- package/lib/private/build/server/plugin/app-request.d.ts +4 -0
- package/lib/private/build/server/plugin/app-request.js +19 -0
- package/lib/private/build/server/plugin/assets.js +9 -7
- package/lib/private/build/server/plugin/config.js +11 -4
- package/lib/private/build/server/plugin/frontend.js +4 -2
- package/lib/private/build/server/plugin/live-reload.d.ts +4 -0
- package/lib/private/build/server/plugin/{hot-reload.js → live-reload.js} +12 -12
- package/lib/private/build/server/plugin/native-addons.js +10 -11
- package/lib/private/build/server/plugin/node-imports.js +2 -2
- package/lib/private/build/server/plugin/route.js +4 -4
- package/lib/private/build/server/plugin/store.js +11 -33
- package/lib/private/build/server/plugin/stores.js +12 -9
- package/lib/private/build/server/plugin/view.js +5 -5
- package/lib/private/build/server/plugin/views.js +4 -4
- package/lib/private/build/server/plugin/virtual-pages.js +8 -8
- package/lib/private/build/server/plugin/virtual-routes.js +8 -13
- package/lib/private/build/server/plugin/wasm.js +2 -3
- package/lib/private/build/shared/plugin/app-request.d.ts +4 -0
- package/lib/private/build/shared/plugin/app-request.js +19 -0
- package/lib/private/bye.js +2 -3
- package/lib/private/client/Data.d.ts +3 -2
- package/lib/private/client/Render.d.ts +8 -0
- package/lib/private/{frontend → client}/ServerData.d.ts +1 -1
- package/lib/private/client/ServerView.d.ts +4 -0
- package/lib/private/client/ValidateInit.d.ts +1 -3
- package/lib/private/client/ValidationError.d.ts +1 -1
- package/lib/private/{frontend → client}/View.d.ts +1 -1
- package/lib/private/{frontend → client}/ViewOptions.d.ts +1 -1
- package/lib/private/{frontend → client}/ViewResponse.d.ts +2 -2
- package/lib/private/client/app.js +3 -3
- package/lib/private/client/boot.d.ts +5 -0
- package/lib/private/client/boot.js +64 -0
- package/lib/private/client/create-form.d.ts +32 -0
- package/lib/private/client/create-form.js +123 -0
- package/lib/private/client/extract-issues.d.ts +4 -0
- package/lib/private/client/extract-issues.js +21 -0
- package/lib/private/client/http.d.ts +13 -0
- package/lib/private/client/http.js +57 -0
- package/lib/private/client/index.d.ts +23 -0
- package/lib/private/client/index.js +16 -0
- package/lib/private/client/navigate.d.ts +13 -0
- package/lib/private/client/navigate.js +67 -0
- package/lib/private/client/root.d.ts +9 -0
- package/lib/private/client/root.js +11 -0
- package/lib/private/client/submit.d.ts +2 -0
- package/lib/private/client/submit.js +41 -0
- package/lib/private/client/{toValidated.d.ts → to-validated.d.ts} +2 -4
- package/lib/private/client/{toValidated.js → to-validated.js} +1 -1
- package/lib/private/client/validate-field.d.ts +3 -0
- package/lib/private/client/validate-field.js +41 -0
- package/lib/private/config/index.d.ts +7 -21
- package/lib/private/config/index.js +4 -1
- package/lib/private/config/schema.d.ts +82 -22
- package/lib/private/config/schema.js +25 -7
- package/lib/private/cookie.d.ts +12 -6
- package/lib/private/cookie.js +10 -14
- package/lib/private/db/As.d.ts +10 -0
- package/lib/private/db/DB.d.ts +49 -0
- package/lib/private/db/DB.js +3 -0
- package/lib/private/db/DataDict.d.ts +5 -0
- package/lib/private/db/DataKey.d.ts +4 -0
- package/lib/private/db/DataValue.d.ts +17 -0
- package/lib/private/db/MemoryDB.d.ts +33 -0
- package/lib/private/db/MemoryDB.js +335 -0
- package/lib/private/db/PK.d.ts +3 -0
- package/lib/private/db/PK.js +2 -0
- package/lib/private/{database → db}/Query.d.ts +2 -2
- package/lib/private/{database → db}/QueryBuilder.d.ts +2 -3
- package/lib/private/db/ReadArgs.d.ts +9 -0
- package/lib/private/db/ReadArgs.js +2 -0
- package/lib/private/db/ReadRelationsArgs.d.ts +6 -0
- package/lib/private/db/ReadRelationsArgs.js +2 -0
- package/lib/private/{database → db}/Schema.d.ts +1 -2
- package/lib/private/db/Sort.d.ts +4 -0
- package/lib/private/{database → db}/TypeMap.d.ts +2 -3
- package/lib/private/{database → db}/Types.d.ts +1 -1
- package/lib/private/db/With.d.ts +16 -0
- package/lib/private/db/With.js +2 -0
- package/lib/private/db/common.d.ts +25 -0
- package/lib/private/db/common.js +67 -0
- package/lib/private/db/errors.d.ts +104 -0
- package/lib/private/db/errors.js +237 -0
- package/lib/private/db/migrate/apply.d.ts +2 -0
- package/lib/private/db/migrate/apply.js +32 -0
- package/lib/private/db/migrate/bundle.d.ts +3 -0
- package/lib/private/db/migrate/bundle.js +22 -0
- package/lib/private/db/migrate/create.d.ts +2 -0
- package/lib/private/db/migrate/create.js +154 -0
- package/lib/private/db/migrate/index.d.ts +10 -0
- package/lib/private/db/migrate/index.js +6 -0
- package/lib/private/db/migrate/status.d.ts +2 -0
- package/lib/private/db/migrate/status.js +38 -0
- package/lib/private/db/migrate/store.d.ts +5 -0
- package/lib/private/db/migrate/store.js +33 -0
- package/lib/private/db/sql.d.ts +28 -0
- package/lib/private/db/sql.js +177 -0
- package/lib/private/db/storage.d.ts +3 -0
- package/lib/private/db/storage.js +3 -0
- package/lib/private/db/symbol.js +2 -0
- package/lib/private/db/test.d.ts +4 -0
- package/lib/private/db/test.js +1750 -0
- package/lib/private/errors.d.ts +88 -0
- package/lib/private/errors.js +211 -0
- package/lib/private/frontend.d.ts +72 -0
- package/lib/private/frontend.js +245 -0
- package/lib/private/hash.js +0 -1
- package/lib/private/i18n/Catalog.d.ts +5 -2
- package/lib/private/i18n/Formatter.js +21 -9
- package/lib/private/i18n/errors.d.ts +16 -0
- package/lib/private/i18n/errors.js +27 -0
- package/lib/private/i18n/format.d.ts +4 -0
- package/lib/private/i18n/format.js +95 -0
- package/lib/private/i18n/index/client.d.ts +9 -0
- package/lib/private/i18n/index/client.js +152 -0
- package/lib/private/i18n/index/server.d.ts +9 -0
- package/lib/private/i18n/index/server.js +57 -0
- package/lib/private/i18n/index/types.d.ts +33 -0
- package/lib/private/i18n/index/types.js +2 -0
- package/lib/private/i18n/locale.d.ts +9 -3
- package/lib/private/i18n/module.d.ts +3 -0
- package/lib/private/i18n/module.js +115 -0
- package/lib/private/i18n/ordinals.d.ts +1 -1
- package/lib/private/i18n/resolve.d.ts +7 -0
- package/lib/private/i18n/resolve.js +30 -0
- package/lib/private/i18n/schema.d.ts +10 -5
- package/lib/private/i18n/schema.js +6 -10
- package/lib/private/i18n/storage.d.ts +3 -0
- package/lib/private/i18n/storage.js +5 -0
- package/lib/private/i18n/validate.d.ts +2 -0
- package/lib/private/i18n/validate.js +19 -0
- package/lib/private/index.d.ts +14 -0
- package/lib/private/index.js +2 -0
- package/lib/private/log.d.ts +1 -0
- package/lib/private/log.js +15 -14
- package/lib/private/module/Hook.d.ts +1 -1
- package/lib/private/module/Next.d.ts +1 -1
- package/lib/private/module/Setup.d.ts +21 -0
- package/lib/private/module/Setup.js +2 -0
- package/lib/private/module/create.d.ts +16 -0
- package/lib/private/module/create.js +28 -0
- package/lib/private/orm/ExtractSchema.d.ts +9 -0
- package/lib/private/orm/ExtractSchema.js +2 -0
- package/lib/private/orm/ForeignKey.d.ts +14 -0
- package/lib/private/orm/ForeignKey.js +25 -0
- package/lib/private/orm/PrimaryKey.d.ts +17 -0
- package/lib/private/orm/PrimaryKey.js +38 -0
- package/lib/private/orm/StoreInput.d.ts +10 -0
- package/lib/private/orm/StoreInput.js +2 -0
- package/lib/private/orm/key.d.ts +8 -0
- package/lib/private/orm/key.js +8 -0
- package/lib/private/orm/parse.d.ts +13 -0
- package/lib/private/orm/parse.js +29 -0
- package/lib/private/orm/relation.d.ts +43 -0
- package/lib/private/orm/relation.js +26 -0
- package/lib/private/orm/store.d.ts +187 -0
- package/lib/private/orm/store.js +542 -0
- package/lib/private/paths.d.ts +2 -2
- package/lib/private/paths.js +3 -3
- package/lib/private/request/RequestBag.d.ts +5 -1
- package/lib/private/request/RequestBag.js +16 -9
- package/lib/private/request/RequestBody.d.ts +6 -11
- package/lib/private/request/RequestBody.js +51 -59
- package/lib/private/request/RequestContext.d.ts +12 -0
- package/lib/private/request/RequestContext.js +31 -0
- package/lib/private/request/RequestFacade.d.ts +11 -6
- package/lib/private/request/RequestPublic.d.ts +9 -0
- package/lib/private/request/RequestPublic.js +2 -0
- package/lib/private/request/RequestView.d.ts +11 -0
- package/lib/private/request/RequestView.js +3 -0
- package/lib/private/request/handle.d.ts +4 -0
- package/lib/private/request/handle.js +18 -0
- package/lib/private/request/parse.d.ts +2 -2
- package/lib/private/request/parse.js +55 -16
- package/lib/private/request/route.js +37 -22
- package/lib/private/request/router.d.ts +1 -1
- package/lib/private/request/router.js +22 -50
- package/lib/private/{database/symbol/wrap.d.ts → request/sContext.d.ts} +1 -1
- package/lib/private/request/sContext.js +2 -0
- package/lib/private/request/storage.d.ts +4 -0
- package/lib/private/request/storage.js +5 -0
- package/lib/private/response/ResponseFunction.d.ts +2 -3
- package/lib/private/response/ResponseLike.d.ts +1 -1
- package/lib/private/response/binary.d.ts +1 -1
- package/lib/private/response/binary.js +4 -3
- package/lib/private/response/error.d.ts +1 -1
- package/lib/private/response/error.js +1 -1
- package/lib/private/response/json.d.ts +1 -1
- package/lib/private/response/json.js +2 -2
- package/lib/private/response/redirect.d.ts +5 -5
- package/lib/private/response/redirect.js +9 -10
- package/lib/private/response/respond.js +16 -17
- package/lib/private/response/sse.d.ts +1 -1
- package/lib/private/response/sse.js +2 -2
- package/lib/private/response/text.d.ts +1 -1
- package/lib/private/response/text.js +3 -3
- package/lib/private/response/view.d.ts +3 -3
- package/lib/private/response/view.js +7 -14
- package/lib/private/response/ws.d.ts +1 -1
- package/lib/private/response.d.ts +1 -1
- package/lib/private/route/Handler.d.ts +1 -1
- package/lib/private/route/hook.d.ts +6 -0
- package/lib/private/route/hook.js +5 -0
- package/lib/private/route/router.d.ts +6 -2
- package/lib/private/route/router.js +32 -18
- package/lib/private/route/wrap.js +2 -2
- package/lib/private/serve/App.d.ts +11 -25
- package/lib/private/serve/App.js +138 -120
- package/lib/private/serve/Init.d.ts +5 -5
- package/lib/private/serve/dev-module.d.ts +2 -0
- package/lib/private/serve/dev-module.js +34 -0
- package/lib/private/serve/hook.d.ts +1 -2
- package/lib/private/serve/hook.js +2 -9
- package/lib/private/serve/index.d.ts +1 -1
- package/lib/private/serve/index.js +36 -2
- package/lib/private/server/TAG.d.ts +3 -0
- package/lib/private/server/TAG.js +2 -0
- package/lib/private/server/index.d.ts +5 -0
- package/lib/private/server/index.js +6 -0
- package/lib/private/session/Data.d.ts +1 -2
- package/lib/private/session/SessionHandle.d.ts +1 -1
- package/lib/private/session/SessionHandle.js +11 -9
- package/lib/private/session/index.d.ts +3 -4
- package/lib/private/session/module.d.ts +3 -0
- package/lib/private/session/module.js +114 -0
- package/lib/private/session/schema.d.ts +17 -9
- package/lib/private/session/schema.js +11 -6
- package/lib/private/session/storage.d.ts +1 -2
- package/lib/private/session/storage.js +2 -2
- package/lib/private/tags.js +2 -2
- package/lib/private/target/Manager.js +6 -12
- package/lib/private/target/Target.d.ts +1 -1
- package/lib/public/AppFacade.d.ts +2 -0
- package/lib/public/AppFacade.js +2 -0
- package/lib/public/build/presets.d.ts +2 -0
- package/lib/public/build/presets.js +2 -0
- package/lib/public/build/transform.d.ts +2 -0
- package/lib/public/build/transform.js +2 -0
- package/lib/public/client.d.ts +3 -0
- package/lib/public/client.js +2 -0
- package/lib/public/db/MemoryDB.d.ts +2 -0
- package/lib/public/db/MemoryDB.js +2 -0
- package/lib/public/db/errors.d.ts +2 -0
- package/lib/public/db/errors.js +2 -0
- package/lib/public/db/migrate.d.ts +2 -0
- package/lib/public/db/migrate.js +2 -0
- package/lib/public/db/sql.d.ts +2 -0
- package/lib/public/db/sql.js +2 -0
- package/lib/public/db/test.d.ts +2 -0
- package/lib/public/db/test.js +2 -0
- package/lib/public/db.d.ts +12 -0
- package/lib/public/db.js +2 -0
- package/lib/public/frontend.d.ts +3 -0
- package/lib/public/frontend.js +2 -0
- package/lib/public/index.d.ts +2 -0
- package/lib/public/index.js +2 -0
- package/lib/public/orm/key.d.ts +2 -0
- package/lib/public/orm/key.js +2 -0
- package/lib/public/orm/relation.d.ts +2 -0
- package/lib/public/orm/relation.js +2 -0
- package/lib/public/orm/store.d.ts +2 -0
- package/lib/public/orm/store.js +2 -0
- package/lib/public/request/server.d.ts +5 -0
- package/lib/public/request/server.js +7 -0
- package/lib/public/response.d.ts +22 -0
- package/lib/public/response.js +19 -0
- package/lib/public/route/hook.d.ts +2 -0
- package/lib/public/route/hook.js +2 -0
- package/lib/public/server.d.ts +3 -0
- package/lib/public/server.js +2 -0
- package/package.json +40 -30
- package/lib/private/AppError.d.ts +0 -4
- package/lib/private/AppError.js +0 -8
- package/lib/private/backend/Module.d.ts +0 -18
- package/lib/private/backend/Module.js +0 -22
- package/lib/private/backend/TAG.d.ts +0 -3
- package/lib/private/backend/TAG.js +0 -2
- package/lib/private/build/client/reload.d.ts +0 -7
- package/lib/private/build/client/reload.js +0 -6
- package/lib/private/build/server/plugin/database-default.d.ts +0 -4
- package/lib/private/build/server/plugin/database-default.js +0 -48
- package/lib/private/build/server/plugin/hot-reload.d.ts +0 -4
- package/lib/private/build/server/plugin/store-wrap.d.ts +0 -4
- package/lib/private/build/server/plugin/store-wrap.js +0 -33
- package/lib/private/client/spa/index.d.ts +0 -6
- package/lib/private/client/spa/index.js +0 -201
- package/lib/private/client/validate.d.ts +0 -3
- package/lib/private/client/validate.js +0 -54
- package/lib/private/database/As.d.ts +0 -7
- package/lib/private/database/Binds.d.ts +0 -4
- package/lib/private/database/Binds.js +0 -2
- package/lib/private/database/Changes.d.ts +0 -11
- package/lib/private/database/Changes.js +0 -2
- package/lib/private/database/ColumnTypes.d.ts +0 -11
- package/lib/private/database/ColumnTypes.js +0 -2
- package/lib/private/database/DataDict.d.ts +0 -5
- package/lib/private/database/DataKey.d.ts +0 -4
- package/lib/private/database/DataValue.d.ts +0 -5
- package/lib/private/database/Database.d.ts +0 -56
- package/lib/private/database/Database.js +0 -153
- package/lib/private/database/InMemoryDatabase.d.ts +0 -37
- package/lib/private/database/InMemoryDatabase.js +0 -181
- package/lib/private/database/Sort.d.ts +0 -4
- package/lib/private/database/Store.d.ts +0 -172
- package/lib/private/database/Store.js +0 -261
- package/lib/private/database/storage.d.ts +0 -4
- package/lib/private/database/storage.js +0 -3
- package/lib/private/database/symbol/wrap.js +0 -2
- package/lib/private/database/symbol.js +0 -2
- package/lib/private/database/test.d.ts +0 -4
- package/lib/private/database/test.js +0 -678
- package/lib/private/database/wrap.d.ts +0 -5
- package/lib/private/database/wrap.js +0 -5
- package/lib/private/fail.d.ts +0 -3
- package/lib/private/fail.js +0 -5
- package/lib/private/frontend/Module.d.ts +0 -62
- package/lib/private/frontend/Module.js +0 -250
- package/lib/private/frontend/Render.d.ts +0 -9
- package/lib/private/frontend/ServerView.d.ts +0 -5
- package/lib/private/i18n/Module.d.ts +0 -16
- package/lib/private/i18n/Module.js +0 -122
- package/lib/private/i18n/index.d.ts +0 -28
- package/lib/private/i18n/index.js +0 -236
- package/lib/private/module/BuildHook.d.ts +0 -5
- package/lib/private/module/BuildHook.js +0 -2
- package/lib/private/module/NextBuild.d.ts +0 -5
- package/lib/private/module/NextBuild.js +0 -2
- package/lib/private/module/NextServe.d.ts +0 -5
- package/lib/private/module/NextServe.js +0 -2
- package/lib/private/reducer.d.ts +0 -24
- package/lib/private/reducer.js +0 -10
- package/lib/private/route/guard.d.ts +0 -4
- package/lib/private/route/guard.js +0 -22
- package/lib/private/serve/module/Dev.d.ts +0 -11
- package/lib/private/serve/module/Dev.js +0 -28
- package/lib/private/serve/module/Handle.d.ts +0 -10
- package/lib/private/serve/module/Handle.js +0 -15
- package/lib/private/session/SessionModule.d.ts +0 -14
- package/lib/private/session/SessionModule.js +0 -122
- package/lib/private/wasm/API.d.ts +0 -7
- package/lib/private/wasm/API.js +0 -2
- package/lib/private/wasm/BufferViewSource.d.ts +0 -4
- package/lib/private/wasm/BufferViewSource.js +0 -2
- package/lib/private/wasm/Exports.d.ts +0 -23
- package/lib/private/wasm/Exports.js +0 -2
- package/lib/private/wasm/I32.d.ts +0 -5
- package/lib/private/wasm/I32.js +0 -2
- package/lib/private/wasm/I32_SIZE.d.ts +0 -3
- package/lib/private/wasm/I32_SIZE.js +0 -2
- package/lib/private/wasm/Instantiation.d.ts +0 -12
- package/lib/private/wasm/Instantiation.js +0 -2
- package/lib/private/wasm/Tagged.d.ts +0 -7
- package/lib/private/wasm/Tagged.js +0 -2
- package/lib/private/wasm/buffersize.d.ts +0 -2
- package/lib/private/wasm/buffersize.js +0 -5
- package/lib/private/wasm/decode-bytes.d.ts +0 -3
- package/lib/private/wasm/decode-bytes.js +0 -5
- package/lib/private/wasm/decode-json.d.ts +0 -7
- package/lib/private/wasm/decode-json.js +0 -11
- package/lib/private/wasm/decode-option.d.ts +0 -5
- package/lib/private/wasm/decode-option.js +0 -10
- package/lib/private/wasm/decode-response.d.ts +0 -19
- package/lib/private/wasm/decode-response.js +0 -90
- package/lib/private/wasm/decode-string.d.ts +0 -3
- package/lib/private/wasm/decode-string.js +0 -5
- package/lib/private/wasm/decode-websocket-close.d.ts +0 -5
- package/lib/private/wasm/decode-websocket-close.js +0 -6
- package/lib/private/wasm/decode-websocket-send.d.ts +0 -6
- package/lib/private/wasm/decode-websocket-send.js +0 -19
- package/lib/private/wasm/encode-buffer.d.ts +0 -3
- package/lib/private/wasm/encode-buffer.js +0 -6
- package/lib/private/wasm/encode-request.d.ts +0 -9
- package/lib/private/wasm/encode-request.js +0 -195
- package/lib/private/wasm/encode-session.d.ts +0 -3
- package/lib/private/wasm/encode-session.js +0 -25
- package/lib/private/wasm/encode-string-map.d.ts +0 -5
- package/lib/private/wasm/encode-string-map.js +0 -14
- package/lib/private/wasm/encode-string.d.ts +0 -13
- package/lib/private/wasm/encode-string.js +0 -17
- package/lib/private/wasm/encode-url.d.ts +0 -11
- package/lib/private/wasm/encode-url.js +0 -14
- package/lib/private/wasm/encode-websocket-close.d.ts +0 -2
- package/lib/private/wasm/encode-websocket-close.js +0 -7
- package/lib/private/wasm/encode-websocket-message.d.ts +0 -4
- package/lib/private/wasm/encode-websocket-message.js +0 -30
- package/lib/private/wasm/encode-websocket-open.d.ts +0 -2
- package/lib/private/wasm/encode-websocket-open.js +0 -7
- package/lib/private/wasm/filesize.d.ts +0 -2
- package/lib/private/wasm/filesize.js +0 -8
- package/lib/private/wasm/instantiate.d.ts +0 -37
- package/lib/private/wasm/instantiate.js +0 -408
- package/lib/private/wasm/open-websocket.d.ts +0 -4
- package/lib/private/wasm/open-websocket.js +0 -26
- package/lib/private/wasm/stringsize.d.ts +0 -3
- package/lib/private/wasm/stringsize.js +0 -5
- package/lib/private/wasm/urlsize.d.ts +0 -2
- package/lib/private/wasm/urlsize.js +0 -5
- package/lib/public/App.d.ts +0 -2
- package/lib/public/App.js +0 -2
- package/lib/public/AppError.d.ts +0 -2
- package/lib/public/AppError.js +0 -2
- package/lib/public/BuildApp.d.ts +0 -2
- package/lib/public/BuildApp.js +0 -2
- package/lib/public/BuildHook.d.ts +0 -2
- package/lib/public/BuildHook.js +0 -2
- package/lib/public/Database.d.ts +0 -2
- package/lib/public/Database.js +0 -2
- package/lib/public/Mode.d.ts +0 -2
- package/lib/public/Mode.js +0 -2
- package/lib/public/Module.d.ts +0 -2
- package/lib/public/Module.js +0 -2
- package/lib/public/Next.d.ts +0 -2
- package/lib/public/Next.js +0 -2
- package/lib/public/NextBuild.d.ts +0 -2
- package/lib/public/NextBuild.js +0 -2
- package/lib/public/NextHandle.d.ts +0 -2
- package/lib/public/NextHandle.js +0 -2
- package/lib/public/NextRoute.d.ts +0 -3
- package/lib/public/NextRoute.js +0 -2
- package/lib/public/NextServe.d.ts +0 -2
- package/lib/public/NextServe.js +0 -2
- package/lib/public/ServeApp.d.ts +0 -2
- package/lib/public/ServeApp.js +0 -2
- package/lib/public/Target.d.ts +0 -2
- package/lib/public/Target.js +0 -2
- package/lib/public/backend/Module.d.ts +0 -2
- package/lib/public/backend/Module.js +0 -2
- package/lib/public/backend/TAG.d.ts +0 -2
- package/lib/public/backend/TAG.js +0 -2
- package/lib/public/client/Data.d.ts +0 -2
- package/lib/public/client/Data.js +0 -2
- package/lib/public/client/ValidateInit.d.ts +0 -2
- package/lib/public/client/ValidateInit.js +0 -2
- package/lib/public/client/ValidateUpdater.d.ts +0 -2
- package/lib/public/client/ValidateUpdater.js +0 -2
- package/lib/public/client/ValidationError.d.ts +0 -2
- package/lib/public/client/ValidationError.js +0 -2
- package/lib/public/client/spa.d.ts +0 -2
- package/lib/public/client/spa.js +0 -2
- package/lib/public/client/toValidated.d.ts +0 -2
- package/lib/public/client/toValidated.js +0 -2
- package/lib/public/client/validate.d.ts +0 -2
- package/lib/public/client/validate.js +0 -2
- package/lib/public/database/As.d.ts +0 -2
- package/lib/public/database/As.js +0 -2
- package/lib/public/database/DataDict.d.ts +0 -2
- package/lib/public/database/DataDict.js +0 -2
- package/lib/public/database/InMemoryDatabase.d.ts +0 -2
- package/lib/public/database/InMemoryDatabase.js +0 -2
- package/lib/public/database/Sort.d.ts +0 -2
- package/lib/public/database/Sort.js +0 -2
- package/lib/public/database/Store.d.ts +0 -2
- package/lib/public/database/Store.js +0 -2
- package/lib/public/database/TypeMap.d.ts +0 -2
- package/lib/public/database/TypeMap.js +0 -2
- package/lib/public/database/Types.d.ts +0 -2
- package/lib/public/database/Types.js +0 -2
- package/lib/public/database/test.d.ts +0 -2
- package/lib/public/database/test.js +0 -2
- package/lib/public/database/wrap.d.ts +0 -2
- package/lib/public/database/wrap.js +0 -2
- package/lib/public/fail.d.ts +0 -2
- package/lib/public/fail.js +0 -2
- package/lib/public/frontend/Module.d.ts +0 -2
- package/lib/public/frontend/Module.js +0 -2
- package/lib/public/frontend/Publish.d.ts +0 -2
- package/lib/public/frontend/Publish.js +0 -2
- package/lib/public/frontend/Render.d.ts +0 -2
- package/lib/public/frontend/Render.js +0 -2
- package/lib/public/frontend/ViewResponse.d.ts +0 -2
- package/lib/public/frontend/ViewResponse.js +0 -2
- package/lib/public/request/RequestBody.d.ts +0 -2
- package/lib/public/request/RequestBody.js +0 -2
- package/lib/public/request/RequestFacade.d.ts +0 -2
- package/lib/public/request/RequestFacade.js +0 -2
- package/lib/public/request/Verb.d.ts +0 -2
- package/lib/public/request/Verb.js +0 -2
- package/lib/public/response/ResponseFunction.d.ts +0 -2
- package/lib/public/response/ResponseFunction.js +0 -2
- package/lib/public/response/ResponseLike.d.ts +0 -2
- package/lib/public/response/ResponseLike.js +0 -2
- package/lib/public/response/binary.d.ts +0 -2
- package/lib/public/response/binary.js +0 -2
- package/lib/public/response/error.d.ts +0 -2
- package/lib/public/response/error.js +0 -2
- package/lib/public/response/json.d.ts +0 -2
- package/lib/public/response/json.js +0 -2
- package/lib/public/response/redirect.d.ts +0 -2
- package/lib/public/response/redirect.js +0 -2
- package/lib/public/response/sse.d.ts +0 -2
- package/lib/public/response/sse.js +0 -2
- package/lib/public/response/text.d.ts +0 -2
- package/lib/public/response/text.js +0 -2
- package/lib/public/response/view.d.ts +0 -2
- package/lib/public/response/view.js +0 -2
- package/lib/public/response/ws.d.ts +0 -2
- package/lib/public/response/ws.js +0 -2
- package/lib/public/wasm/decode-json.d.ts +0 -5
- package/lib/public/wasm/decode-json.js +0 -3
- package/lib/public/wasm/decode-response.d.ts +0 -3
- package/lib/public/wasm/decode-response.js +0 -3
- package/lib/public/wasm/encode-request.d.ts +0 -3
- package/lib/public/wasm/encode-request.js +0 -3
- package/lib/public/wasm/encode-session.d.ts +0 -3
- package/lib/public/wasm/encode-session.js +0 -3
- package/lib/public/wasm/instantiate.d.ts +0 -4
- package/lib/public/wasm/instantiate.js +0 -3
- /package/lib/private/{frontend → client}/Publish.d.ts +0 -0
- /package/lib/private/{frontend → client}/Publish.js +0 -0
- /package/lib/private/{frontend → client}/Render.js +0 -0
- /package/lib/private/{frontend → client}/ServerData.js +0 -0
- /package/lib/private/{frontend → client}/ServerView.js +0 -0
- /package/lib/private/{frontend → client}/View.js +0 -0
- /package/lib/private/{frontend → client}/ViewOptions.js +0 -0
- /package/lib/private/{frontend → client}/ViewResponse.js +0 -0
- /package/lib/private/client/{spa/storage.d.ts → storage.d.ts} +0 -0
- /package/lib/private/client/{spa/storage.js → storage.js} +0 -0
- /package/lib/private/{database → db}/As.js +0 -0
- /package/lib/private/{database → db}/DataDict.js +0 -0
- /package/lib/private/{database → db}/DataKey.js +0 -0
- /package/lib/private/{database → db}/DataValue.js +0 -0
- /package/lib/private/{database → db}/Query.js +0 -0
- /package/lib/private/{database → db}/QueryBuilder.js +0 -0
- /package/lib/private/{database → db}/Schema.js +0 -0
- /package/lib/private/{database → db}/Sort.js +0 -0
- /package/lib/private/{database → db}/TypeMap.js +0 -0
- /package/lib/private/{database → db}/Types.js +0 -0
- /package/lib/private/{database → db}/primary.d.ts +0 -0
- /package/lib/private/{database → db}/primary.js +0 -0
- /package/lib/private/{database → db}/symbol.d.ts +0 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type As from "#db/As";
|
|
2
|
+
import type ReadArgs from "#db/ReadArgs";
|
|
3
|
+
import type ReadRelationsArgs from "#db/ReadRelationsArgs";
|
|
4
|
+
import type With from "#db/With";
|
|
5
|
+
import type { Dict } from "@rcompat/type";
|
|
6
|
+
import type { DataKey } from "pema";
|
|
7
|
+
declare const UUID_TYPES: DataKey[];
|
|
8
|
+
declare function generate_uuid(type: typeof UUID_TYPES[number]): string;
|
|
9
|
+
declare function is_uuid_type(type: DataKey): type is typeof UUID_TYPES[number];
|
|
10
|
+
declare const BASE: {
|
|
11
|
+
withed(args: ReadArgs & {
|
|
12
|
+
with?: With;
|
|
13
|
+
}): args is ReadRelationsArgs;
|
|
14
|
+
fields(base: string[] | undefined, ...add: (string | null)[]): string[] | undefined;
|
|
15
|
+
project(row: Dict, fields?: string[]): Dict;
|
|
16
|
+
expand(as: As, fields: string[] | undefined, relations: With): string[] | undefined;
|
|
17
|
+
generate_uuid: typeof generate_uuid;
|
|
18
|
+
is_uuid_type: typeof is_uuid_type;
|
|
19
|
+
BIGINT_STRING_TYPES: string[];
|
|
20
|
+
UNSIGNED_BIGINT_TYPES: string[];
|
|
21
|
+
INT_TYPES: string[];
|
|
22
|
+
UUID_TYPES: (keyof import("pema").DataType)[];
|
|
23
|
+
};
|
|
24
|
+
export default BASE;
|
|
25
|
+
//# sourceMappingURL=common.d.ts.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const UNSIGNED_BIGINT_TYPES = ["u64", "u128"];
|
|
2
|
+
const SIGNED_BIGINT_TYPES = ["i128"];
|
|
3
|
+
const BIGINT_STRING_TYPES = [...UNSIGNED_BIGINT_TYPES, ...SIGNED_BIGINT_TYPES];
|
|
4
|
+
const INT_TYPES = ["u8", "u16", "u32", "i8", "i16", "i32"];
|
|
5
|
+
const UUID_TYPES = ["uuid", "uuid_v4", "uuid_v7"];
|
|
6
|
+
function uuid_v7() {
|
|
7
|
+
const bytes = crypto.getRandomValues(new Uint8Array(16));
|
|
8
|
+
const ts = BigInt(Date.now());
|
|
9
|
+
bytes[0] = Number((ts >> 40n) & 0xffn);
|
|
10
|
+
bytes[1] = Number((ts >> 32n) & 0xffn);
|
|
11
|
+
bytes[2] = Number((ts >> 24n) & 0xffn);
|
|
12
|
+
bytes[3] = Number((ts >> 16n) & 0xffn);
|
|
13
|
+
bytes[4] = Number((ts >> 8n) & 0xffn);
|
|
14
|
+
bytes[5] = Number(ts & 0xffn);
|
|
15
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x70; // version 7
|
|
16
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80; // variant
|
|
17
|
+
const hex = bytes.toHex();
|
|
18
|
+
return (hex.slice(0, 8) + "-" +
|
|
19
|
+
hex.slice(8, 12) + "-" +
|
|
20
|
+
hex.slice(12, 16) + "-" +
|
|
21
|
+
hex.slice(16, 20) + "-" +
|
|
22
|
+
hex.slice(20));
|
|
23
|
+
}
|
|
24
|
+
function generate_uuid(type) {
|
|
25
|
+
if (type === "uuid_v4")
|
|
26
|
+
return crypto.randomUUID();
|
|
27
|
+
// "uuid" and "uuid_v7" both use v7 as the best native choice
|
|
28
|
+
return uuid_v7();
|
|
29
|
+
}
|
|
30
|
+
function is_uuid_type(type) {
|
|
31
|
+
return UUID_TYPES.includes(type);
|
|
32
|
+
}
|
|
33
|
+
const BASE = {
|
|
34
|
+
withed(args) {
|
|
35
|
+
return args.with !== undefined;
|
|
36
|
+
},
|
|
37
|
+
fields(base, ...add) {
|
|
38
|
+
if (base === undefined)
|
|
39
|
+
return undefined;
|
|
40
|
+
const set = new Set(base);
|
|
41
|
+
for (const f of add)
|
|
42
|
+
if (f !== null)
|
|
43
|
+
set.add(f);
|
|
44
|
+
return [...set];
|
|
45
|
+
},
|
|
46
|
+
project(row, fields) {
|
|
47
|
+
if (fields === undefined || fields.length === 0)
|
|
48
|
+
return { ...row };
|
|
49
|
+
const out = {};
|
|
50
|
+
for (const k of fields)
|
|
51
|
+
if (k in row)
|
|
52
|
+
out[k] = row[k];
|
|
53
|
+
return out;
|
|
54
|
+
},
|
|
55
|
+
expand(as, fields, relations) {
|
|
56
|
+
const fks = Object.values(relations).flatMap(r => r.reverse ? [r.fk] : []);
|
|
57
|
+
return BASE.fields(fields, as.pk, ...fks);
|
|
58
|
+
},
|
|
59
|
+
generate_uuid,
|
|
60
|
+
is_uuid_type,
|
|
61
|
+
BIGINT_STRING_TYPES,
|
|
62
|
+
UNSIGNED_BIGINT_TYPES,
|
|
63
|
+
INT_TYPES,
|
|
64
|
+
UUID_TYPES,
|
|
65
|
+
};
|
|
66
|
+
export default BASE;
|
|
67
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
declare function db_missing(): import("@rcompat/error").TemplateError;
|
|
2
|
+
declare function store_directory_missing(): import("@rcompat/error").TemplateError;
|
|
3
|
+
declare function store_directory_empty(): import("@rcompat/error").TemplateError;
|
|
4
|
+
declare function store_name_required(): import("@rcompat/error").TemplateError;
|
|
5
|
+
declare function unregistered_schema(): import("@rcompat/error").TemplateError;
|
|
6
|
+
declare function record_not_found(field: string, value: string | number | bigint): import("@rcompat/error").TemplateError;
|
|
7
|
+
declare function key_duplicate(key: string): import("@rcompat/error").TemplateError;
|
|
8
|
+
declare function table_not_found(table: string): import("@rcompat/error").TemplateError;
|
|
9
|
+
type RecordCountInvalidContext = "get" | "update" | "delete" | "count";
|
|
10
|
+
declare function record_number_invalid(n: number, context: RecordCountInvalidContext): import("@rcompat/error").TemplateError;
|
|
11
|
+
declare function return_invalid(got: unknown, expected: string, context: RecordCountInvalidContext): import("@rcompat/error").TemplateError;
|
|
12
|
+
declare function pk_undefined(store: string): import("@rcompat/error").TemplateError;
|
|
13
|
+
declare function pk_immutable(pk: string): import("@rcompat/error").TemplateError;
|
|
14
|
+
declare function pk_duplicate(pk: string): import("@rcompat/error").TemplateError;
|
|
15
|
+
declare function pk_invalid(pk: unknown): import("@rcompat/error").TemplateError;
|
|
16
|
+
declare function pk_required(table: string): import("@rcompat/error").TemplateError;
|
|
17
|
+
declare function pk_multiple_pks(first: string, second: string): import("@rcompat/error").TemplateError;
|
|
18
|
+
declare function pk_invalid_type(datatype: string): import("@rcompat/error").TemplateError;
|
|
19
|
+
type Context = "select" | "where" | "sort" | "insert" | "set" | "unbind";
|
|
20
|
+
declare function field_unknown(field: string, context: Context): import("@rcompat/error").TemplateError;
|
|
21
|
+
declare function field_duplicate(field: string, context: Context): import("@rcompat/error").TemplateError;
|
|
22
|
+
declare function field_required(operator: string): import("@rcompat/error").TemplateError;
|
|
23
|
+
declare function field_undefined(field: string, context: Context): import("@rcompat/error").TemplateError;
|
|
24
|
+
declare function fields_unknown(fields: string[]): import("@rcompat/error").TemplateError;
|
|
25
|
+
declare function null_not_allowed(field: string): import("@rcompat/error").TemplateError;
|
|
26
|
+
declare function wrong_type(type: "string" | "number" | "bigint" | "boolean" | "url" | "date" | "blob", field: string, got: unknown, op?: string): import("@rcompat/error").TemplateError;
|
|
27
|
+
declare function operator_unknown(field: string, operator: string): import("@rcompat/error").TemplateError;
|
|
28
|
+
declare function operator_empty(field: string): import("@rcompat/error").TemplateError;
|
|
29
|
+
declare function operator_scalar(field: string): import("@rcompat/error").TemplateError;
|
|
30
|
+
declare function sort_empty(): import("@rcompat/error").TemplateError;
|
|
31
|
+
declare function sort_invalid(): import("@rcompat/error").TemplateError;
|
|
32
|
+
declare function sort_invalid_value(field: string, value: unknown): import("@rcompat/error").TemplateError;
|
|
33
|
+
declare function select_empty(): import("@rcompat/error").TemplateError;
|
|
34
|
+
declare function select_invalid(): import("@rcompat/error").TemplateError;
|
|
35
|
+
declare function limit_invalid(): import("@rcompat/error").TemplateError;
|
|
36
|
+
declare function select_invalid_value(index: number, x: unknown): import("@rcompat/error").TemplateError;
|
|
37
|
+
declare function where_required(): import("@rcompat/error").TemplateError;
|
|
38
|
+
declare function where_invalid(): import("@rcompat/error").TemplateError;
|
|
39
|
+
declare function where_invalid_value(field: string, value: unknown): import("@rcompat/error").TemplateError;
|
|
40
|
+
declare function set_empty(): import("@rcompat/error").TemplateError;
|
|
41
|
+
declare function relation_unknown(relation: string): import("@rcompat/error").TemplateError;
|
|
42
|
+
declare function relation_requires_pk(type: "target" | "parent"): import("@rcompat/error").TemplateError;
|
|
43
|
+
declare function relation_conflicts_with_field(relation: string): import("@rcompat/error").TemplateError;
|
|
44
|
+
declare function option_unknown(option: string): import("@rcompat/error").TemplateError;
|
|
45
|
+
declare function identifier_invalid(identifier: string): import("@rcompat/error").TemplateError;
|
|
46
|
+
declare function count_with_invalid(): import("@rcompat/error").TemplateError;
|
|
47
|
+
declare function count_overflow(table: string, count: unknown): import("@rcompat/error").TemplateError;
|
|
48
|
+
declare function migration_directory_missing(): import("@rcompat/error").TemplateError;
|
|
49
|
+
declare function migration_store_conflict(message: string): import("@rcompat/error").TemplateError;
|
|
50
|
+
declare function unapplied_migrations(): import("@rcompat/error").TemplateError;
|
|
51
|
+
declare const errors: {
|
|
52
|
+
option_unknown: typeof option_unknown;
|
|
53
|
+
identifier_invalid: typeof identifier_invalid;
|
|
54
|
+
count_with_invalid: typeof count_with_invalid;
|
|
55
|
+
count_overflow: typeof count_overflow;
|
|
56
|
+
migration_directory_missing: typeof migration_directory_missing;
|
|
57
|
+
migration_store_conflict: typeof migration_store_conflict;
|
|
58
|
+
unapplied_migrations: typeof unapplied_migrations;
|
|
59
|
+
relation_unknown: typeof relation_unknown;
|
|
60
|
+
relation_requires_pk: typeof relation_requires_pk;
|
|
61
|
+
relation_conflicts_with_field: typeof relation_conflicts_with_field;
|
|
62
|
+
sort_empty: typeof sort_empty;
|
|
63
|
+
sort_invalid: typeof sort_invalid;
|
|
64
|
+
sort_invalid_value: typeof sort_invalid_value;
|
|
65
|
+
select_empty: typeof select_empty;
|
|
66
|
+
select_invalid: typeof select_invalid;
|
|
67
|
+
select_invalid_value: typeof select_invalid_value;
|
|
68
|
+
where_required: typeof where_required;
|
|
69
|
+
where_invalid: typeof where_invalid;
|
|
70
|
+
where_invalid_value: typeof where_invalid_value;
|
|
71
|
+
set_empty: typeof set_empty;
|
|
72
|
+
limit_invalid: typeof limit_invalid;
|
|
73
|
+
operator_unknown: typeof operator_unknown;
|
|
74
|
+
operator_empty: typeof operator_empty;
|
|
75
|
+
wrong_type: typeof wrong_type;
|
|
76
|
+
operator_scalar: typeof operator_scalar;
|
|
77
|
+
null_not_allowed: typeof null_not_allowed;
|
|
78
|
+
field_unknown: typeof field_unknown;
|
|
79
|
+
field_duplicate: typeof field_duplicate;
|
|
80
|
+
field_required: typeof field_required;
|
|
81
|
+
field_undefined: typeof field_undefined;
|
|
82
|
+
fields_unknown: typeof fields_unknown;
|
|
83
|
+
pk_undefined: typeof pk_undefined;
|
|
84
|
+
pk_immutable: typeof pk_immutable;
|
|
85
|
+
pk_duplicate: typeof pk_duplicate;
|
|
86
|
+
pk_invalid: typeof pk_invalid;
|
|
87
|
+
pk_required: typeof pk_required;
|
|
88
|
+
pk_multiple_pks: typeof pk_multiple_pks;
|
|
89
|
+
pk_invalid_type: typeof pk_invalid_type;
|
|
90
|
+
db_missing: typeof db_missing;
|
|
91
|
+
store_directory_missing: typeof store_directory_missing;
|
|
92
|
+
store_directory_empty: typeof store_directory_empty;
|
|
93
|
+
store_name_required: typeof store_name_required;
|
|
94
|
+
unregistered_schema: typeof unregistered_schema;
|
|
95
|
+
record_not_found: typeof record_not_found;
|
|
96
|
+
record_number_invalid: typeof record_number_invalid;
|
|
97
|
+
return_invalid: typeof return_invalid;
|
|
98
|
+
key_duplicate: typeof key_duplicate;
|
|
99
|
+
table_not_found: typeof table_not_found;
|
|
100
|
+
};
|
|
101
|
+
export type Code = keyof typeof errors;
|
|
102
|
+
export declare const Code: { [K in Code]: K; };
|
|
103
|
+
export default errors;
|
|
104
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import error from "@rcompat/error";
|
|
2
|
+
const MAX_INT = Number.MAX_SAFE_INTEGER;
|
|
3
|
+
const t = error.template;
|
|
4
|
+
function kind_of(x) {
|
|
5
|
+
if (x === null)
|
|
6
|
+
return "null";
|
|
7
|
+
if (x instanceof Date)
|
|
8
|
+
return "Date";
|
|
9
|
+
if (x instanceof URL)
|
|
10
|
+
return "URL";
|
|
11
|
+
if (x instanceof Blob)
|
|
12
|
+
return "Blob";
|
|
13
|
+
return typeof x;
|
|
14
|
+
}
|
|
15
|
+
function db_missing() {
|
|
16
|
+
return t `database missing`;
|
|
17
|
+
}
|
|
18
|
+
function store_directory_missing() {
|
|
19
|
+
return t `store directory missing`;
|
|
20
|
+
}
|
|
21
|
+
function store_directory_empty() {
|
|
22
|
+
return t `store directory empty`;
|
|
23
|
+
}
|
|
24
|
+
function store_name_required() {
|
|
25
|
+
return t `store name required`;
|
|
26
|
+
}
|
|
27
|
+
function unregistered_schema() {
|
|
28
|
+
return t `no store registered for schema`;
|
|
29
|
+
}
|
|
30
|
+
function record_not_found(field, value) {
|
|
31
|
+
return t `no record with ${field} = ${value}`;
|
|
32
|
+
}
|
|
33
|
+
function key_duplicate(key) {
|
|
34
|
+
return t `key ${key} already exists`;
|
|
35
|
+
}
|
|
36
|
+
function table_not_found(table) {
|
|
37
|
+
return t `table ${table} not found`;
|
|
38
|
+
}
|
|
39
|
+
function record_number_invalid(n, context) {
|
|
40
|
+
return t `${context}: record number invalid (${n} instead of 1)`;
|
|
41
|
+
}
|
|
42
|
+
function return_invalid(got, expected, context) {
|
|
43
|
+
return t `${context} returned ${typeof got}, expected ${expected}`;
|
|
44
|
+
}
|
|
45
|
+
const STORE = error.coded({
|
|
46
|
+
db_missing,
|
|
47
|
+
store_directory_missing,
|
|
48
|
+
store_directory_empty,
|
|
49
|
+
store_name_required,
|
|
50
|
+
unregistered_schema,
|
|
51
|
+
record_not_found,
|
|
52
|
+
record_number_invalid,
|
|
53
|
+
return_invalid,
|
|
54
|
+
key_duplicate,
|
|
55
|
+
table_not_found,
|
|
56
|
+
});
|
|
57
|
+
function pk_undefined(store) {
|
|
58
|
+
return t `${store}: store has no primary key`;
|
|
59
|
+
}
|
|
60
|
+
function pk_immutable(pk) {
|
|
61
|
+
return t `primary key ${pk} cannot be updated`;
|
|
62
|
+
}
|
|
63
|
+
function pk_duplicate(pk) {
|
|
64
|
+
return t `primary key ${pk} already exists`;
|
|
65
|
+
}
|
|
66
|
+
function pk_invalid(pk) {
|
|
67
|
+
return t `pk value ${pk} (${kind_of(pk)}) does not match the expected type`;
|
|
68
|
+
}
|
|
69
|
+
function pk_required(table) {
|
|
70
|
+
return t `primary key is required but has generate=${false} in table ${table}`;
|
|
71
|
+
}
|
|
72
|
+
function pk_multiple_pks(first, second) {
|
|
73
|
+
return t `multiple primary keys: ${first}, ${second}`;
|
|
74
|
+
}
|
|
75
|
+
function pk_invalid_type(datatype) {
|
|
76
|
+
return t `primary key type ${datatype} not allowed; use unsigned integers or p.uuid`;
|
|
77
|
+
}
|
|
78
|
+
const PK = error.coded({
|
|
79
|
+
pk_undefined,
|
|
80
|
+
pk_immutable,
|
|
81
|
+
pk_duplicate,
|
|
82
|
+
pk_invalid,
|
|
83
|
+
pk_required,
|
|
84
|
+
pk_multiple_pks,
|
|
85
|
+
pk_invalid_type,
|
|
86
|
+
});
|
|
87
|
+
function field_unknown(field, context) {
|
|
88
|
+
return t `${field}: unknown field on ${context}`;
|
|
89
|
+
}
|
|
90
|
+
function field_duplicate(field, context) {
|
|
91
|
+
return t `${field}: duplicate field on ${context}`;
|
|
92
|
+
}
|
|
93
|
+
function field_required(operator) {
|
|
94
|
+
return t `${operator}: at least one field required`;
|
|
95
|
+
}
|
|
96
|
+
function field_undefined(field, context) {
|
|
97
|
+
return t `${field}: undefined value on ${context}`;
|
|
98
|
+
}
|
|
99
|
+
function fields_unknown(fields) {
|
|
100
|
+
return t `unknown fields ${fields}`;
|
|
101
|
+
}
|
|
102
|
+
const FIELD = error.coded({
|
|
103
|
+
field_unknown,
|
|
104
|
+
field_duplicate,
|
|
105
|
+
field_required,
|
|
106
|
+
field_undefined,
|
|
107
|
+
fields_unknown,
|
|
108
|
+
});
|
|
109
|
+
function null_not_allowed(field) {
|
|
110
|
+
return t `${field}: null not allowed`;
|
|
111
|
+
}
|
|
112
|
+
const NULL = error.coded({
|
|
113
|
+
null_not_allowed,
|
|
114
|
+
});
|
|
115
|
+
function wrong_type(type, field, got, op = "value") {
|
|
116
|
+
return t `${field}: ${op} requires ${type}, got ${kind_of(got)}`;
|
|
117
|
+
}
|
|
118
|
+
function operator_unknown(field, operator) {
|
|
119
|
+
return t `${field}: unknown operator ${operator}`;
|
|
120
|
+
}
|
|
121
|
+
function operator_empty(field) {
|
|
122
|
+
return t `${field}: empty operator`;
|
|
123
|
+
}
|
|
124
|
+
function operator_scalar(field) {
|
|
125
|
+
return t `${field}: operator requires scalar value`;
|
|
126
|
+
}
|
|
127
|
+
const OPERATOR = error.coded({
|
|
128
|
+
operator_unknown,
|
|
129
|
+
operator_empty,
|
|
130
|
+
wrong_type,
|
|
131
|
+
operator_scalar,
|
|
132
|
+
});
|
|
133
|
+
function sort_empty() {
|
|
134
|
+
return t `empty sort`;
|
|
135
|
+
}
|
|
136
|
+
function sort_invalid() {
|
|
137
|
+
return t `sort invalid`;
|
|
138
|
+
}
|
|
139
|
+
function sort_invalid_value(field, value) {
|
|
140
|
+
return t `${field}: invalid sort value, received ${kind_of(value)}`;
|
|
141
|
+
}
|
|
142
|
+
function select_empty() {
|
|
143
|
+
return t `empty select`;
|
|
144
|
+
}
|
|
145
|
+
function select_invalid() {
|
|
146
|
+
return t `invalid select`;
|
|
147
|
+
}
|
|
148
|
+
function limit_invalid() {
|
|
149
|
+
return t `invalid limit`;
|
|
150
|
+
}
|
|
151
|
+
function select_invalid_value(index, x) {
|
|
152
|
+
return t `select[${index}]: must be string, received ${kind_of(x)}`;
|
|
153
|
+
}
|
|
154
|
+
function where_required() {
|
|
155
|
+
return t `where required`;
|
|
156
|
+
}
|
|
157
|
+
function where_invalid() {
|
|
158
|
+
return t `where invalid`;
|
|
159
|
+
}
|
|
160
|
+
function where_invalid_value(field, value) {
|
|
161
|
+
return t `${field}: invalid where value, received ${kind_of(value)}`;
|
|
162
|
+
}
|
|
163
|
+
function set_empty() {
|
|
164
|
+
return t `empty set on update`;
|
|
165
|
+
}
|
|
166
|
+
const QUERY = error.coded({
|
|
167
|
+
sort_empty,
|
|
168
|
+
sort_invalid,
|
|
169
|
+
sort_invalid_value,
|
|
170
|
+
select_empty,
|
|
171
|
+
select_invalid,
|
|
172
|
+
select_invalid_value,
|
|
173
|
+
where_required,
|
|
174
|
+
where_invalid,
|
|
175
|
+
where_invalid_value,
|
|
176
|
+
set_empty,
|
|
177
|
+
limit_invalid,
|
|
178
|
+
});
|
|
179
|
+
function relation_unknown(relation) {
|
|
180
|
+
return t `unknown relation ${relation}`;
|
|
181
|
+
}
|
|
182
|
+
function relation_requires_pk(type) {
|
|
183
|
+
return t `relation loading requires ${type} primary key`;
|
|
184
|
+
}
|
|
185
|
+
function relation_conflicts_with_field(relation) {
|
|
186
|
+
return t `relation ${relation} conflicts with an existing schema field`;
|
|
187
|
+
}
|
|
188
|
+
const RELATION = error.coded({
|
|
189
|
+
relation_unknown,
|
|
190
|
+
relation_requires_pk,
|
|
191
|
+
relation_conflicts_with_field,
|
|
192
|
+
});
|
|
193
|
+
function option_unknown(option) {
|
|
194
|
+
return t `unknown option ${option}`;
|
|
195
|
+
}
|
|
196
|
+
function identifier_invalid(identifier) {
|
|
197
|
+
return t `invalid identifier ${identifier}`;
|
|
198
|
+
}
|
|
199
|
+
function count_with_invalid() {
|
|
200
|
+
return t `${"count"} and ${"with"} are mutually exclusive`;
|
|
201
|
+
}
|
|
202
|
+
function count_overflow(table, count) {
|
|
203
|
+
return t `${table}: count overflow, received ${count} (max ${MAX_INT})`;
|
|
204
|
+
}
|
|
205
|
+
function migration_directory_missing() {
|
|
206
|
+
return t `missing ${"migrations"} directory`;
|
|
207
|
+
}
|
|
208
|
+
function migration_store_conflict(message) {
|
|
209
|
+
return t `multiple migratable stores share the same table:\n${message}`;
|
|
210
|
+
}
|
|
211
|
+
function unapplied_migrations() {
|
|
212
|
+
return t `You have unapplied migrations.
|
|
213
|
+
— Show migration status ${"npx primate migrate:status"}
|
|
214
|
+
- Apply pending migrations ${"npx primate migrate:apply"}`;
|
|
215
|
+
}
|
|
216
|
+
const MISC = error.coded({
|
|
217
|
+
option_unknown,
|
|
218
|
+
identifier_invalid,
|
|
219
|
+
count_with_invalid,
|
|
220
|
+
count_overflow,
|
|
221
|
+
migration_directory_missing,
|
|
222
|
+
migration_store_conflict,
|
|
223
|
+
unapplied_migrations,
|
|
224
|
+
});
|
|
225
|
+
const errors = {
|
|
226
|
+
...STORE,
|
|
227
|
+
...PK,
|
|
228
|
+
...FIELD,
|
|
229
|
+
...NULL,
|
|
230
|
+
...OPERATOR,
|
|
231
|
+
...QUERY,
|
|
232
|
+
...RELATION,
|
|
233
|
+
...MISC,
|
|
234
|
+
};
|
|
235
|
+
export const Code = Object.fromEntries(Object.keys(errors).map(k => [k, k]));
|
|
236
|
+
export default errors;
|
|
237
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import E from "#db/errors";
|
|
2
|
+
import store from "#db/migrate/store";
|
|
3
|
+
import color from "@rcompat/cli/color";
|
|
4
|
+
import print from "@rcompat/cli/print";
|
|
5
|
+
import fs from "@rcompat/fs";
|
|
6
|
+
export default async function apply_migration() {
|
|
7
|
+
const Migration = await store();
|
|
8
|
+
await Migration.table.create();
|
|
9
|
+
const last = await Migration.find({ limit: 1, sort: { id: "desc" } });
|
|
10
|
+
const last_id = last.length === 0 ? 0 : last[0].id;
|
|
11
|
+
const root = await fs.project.root();
|
|
12
|
+
const migrations_dir = root.join("migrations");
|
|
13
|
+
if (!await migrations_dir.exists())
|
|
14
|
+
throw E.migration_directory_missing();
|
|
15
|
+
const files = (await migrations_dir.files({ filter: /\d+-.*\.[jt]s$/ }))
|
|
16
|
+
.map(f => ({ file: f, n: parseInt(f.name.split("-")[0]) }))
|
|
17
|
+
.filter(({ n }) => n > last_id)
|
|
18
|
+
.toSorted((a, b) => a.n - b.n);
|
|
19
|
+
if (files.length === 0) {
|
|
20
|
+
print("No pending migrations.\n");
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
for (const { file, n } of files) {
|
|
24
|
+
const { default: migration } = await import(file.path);
|
|
25
|
+
await migration(Migration.db);
|
|
26
|
+
await Migration.insert({ id: n, applied: new Date() });
|
|
27
|
+
print(`Applied migration ${color.bold(file.name)}.\n`);
|
|
28
|
+
}
|
|
29
|
+
const plural = files.length === 1 ? "" : "s";
|
|
30
|
+
print(`Done. Applied ${files.length} migration${plural}.\n`);
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=apply.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import fs from "@rcompat/fs";
|
|
2
|
+
import esbuild from "esbuild";
|
|
3
|
+
export default async (contents) => {
|
|
4
|
+
const root = await fs.project.root();
|
|
5
|
+
const id = Date.now();
|
|
6
|
+
const entrypoint = root.join(`.migrate-in-${id}.js`);
|
|
7
|
+
const out = root.join(`.migrate-out-${id}.js`);
|
|
8
|
+
await entrypoint.write(contents);
|
|
9
|
+
esbuild.buildSync({
|
|
10
|
+
entryPoints: [entrypoint.path],
|
|
11
|
+
outfile: out.path,
|
|
12
|
+
bundle: true,
|
|
13
|
+
format: "esm",
|
|
14
|
+
platform: "node",
|
|
15
|
+
tsconfig: root.join("tsconfig.json").path,
|
|
16
|
+
});
|
|
17
|
+
await entrypoint.remove();
|
|
18
|
+
const result = await out.import("default");
|
|
19
|
+
await out.remove();
|
|
20
|
+
return result;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=bundle.js.map
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import E from "#db/errors";
|
|
2
|
+
import bundle from "#db/migrate/bundle";
|
|
3
|
+
import store from "#db/migrate/store";
|
|
4
|
+
import c from "@rcompat/cli/color";
|
|
5
|
+
import print from "@rcompat/cli/print";
|
|
6
|
+
import is_cancel from "@rcompat/cli/prompts/is-cancel";
|
|
7
|
+
import text from "@rcompat/cli/prompts/text";
|
|
8
|
+
import fs from "@rcompat/fs";
|
|
9
|
+
import string from "@rcompat/string";
|
|
10
|
+
function generate_migration(diffs) {
|
|
11
|
+
const lines = ["export default async db => {"];
|
|
12
|
+
for (const entry of diffs) {
|
|
13
|
+
if (entry.op === "create") {
|
|
14
|
+
const { store } = entry;
|
|
15
|
+
const types = Object.entries(store.types)
|
|
16
|
+
.map(([k, v]) => ` ${k}: "${v}"`)
|
|
17
|
+
.join(",\n");
|
|
18
|
+
const options = `{ name: "${store.pk}", generate: true }`;
|
|
19
|
+
lines.push(` await db.schema.create("${store.name}", ${options}, {`);
|
|
20
|
+
lines.push(`${types}`);
|
|
21
|
+
lines.push(" });");
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
const { store, diff } = entry;
|
|
25
|
+
lines.push(` await db.schema.alter("${store.name}", {`);
|
|
26
|
+
lines.push(` add: { ${Object.entries(diff.add).map(([k, v]) => `${k}: "${v}"`).join(", ")} },`);
|
|
27
|
+
lines.push(` drop: [${diff.drop.map(f => `"${f}"`).join(", ")}],`);
|
|
28
|
+
lines.push(` rename: [${diff.rename.map(([f, t]) => `["${f}", "${t}"]`).join(", ")}],`);
|
|
29
|
+
lines.push(" });");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
lines.push("};");
|
|
33
|
+
return lines.join("\n");
|
|
34
|
+
}
|
|
35
|
+
export default async function create_migration(desc) {
|
|
36
|
+
const root = await fs.project.root();
|
|
37
|
+
const migrations = root.join("migrations");
|
|
38
|
+
// discover store files
|
|
39
|
+
const stores_dir = root.join("stores");
|
|
40
|
+
if (!await stores_dir.exists())
|
|
41
|
+
throw E.store_directory_missing();
|
|
42
|
+
const store_files = await stores_dir.files({
|
|
43
|
+
recursive: true,
|
|
44
|
+
filter: /\.[jt]s$/,
|
|
45
|
+
});
|
|
46
|
+
if (store_files.length === 0)
|
|
47
|
+
throw E.store_directory_empty();
|
|
48
|
+
let next = 1;
|
|
49
|
+
if (await migrations.exists()) {
|
|
50
|
+
const Migration = await store();
|
|
51
|
+
await Migration.table.create();
|
|
52
|
+
const last = await Migration.find({ limit: 1, sort: { id: "desc" } });
|
|
53
|
+
const last_id = last.length === 0 ? 0 : last[0].id;
|
|
54
|
+
const files = await migrations.files({ filter: /\d+-.*\.ts$/ });
|
|
55
|
+
const highest = files.length === 0 ? 0 : Math.max(...files.map(f => parseInt(f.name.split("-")[0])));
|
|
56
|
+
if (highest > last_id)
|
|
57
|
+
throw E.unapplied_migrations();
|
|
58
|
+
next = highest + 1;
|
|
59
|
+
}
|
|
60
|
+
// generate virtual entry
|
|
61
|
+
const entry = store_files.map((f, i) => `import s${i} from "${f.path}";`).join("\n") + `\nexport default [
|
|
62
|
+
${store_files.map((_, i) => `s${i}`).join(",\n ")}\n];`;
|
|
63
|
+
const stores = await bundle(entry);
|
|
64
|
+
const diffs = [];
|
|
65
|
+
const migration_stores = stores.filter(s => s.migrate);
|
|
66
|
+
const names = new Map();
|
|
67
|
+
for (let i = 0; i < store_files.length; i++) {
|
|
68
|
+
const file = store_files[i];
|
|
69
|
+
const store = stores[i];
|
|
70
|
+
if (!store.migrate)
|
|
71
|
+
continue;
|
|
72
|
+
const existing = names.get(store.name) ?? [];
|
|
73
|
+
names.set(store.name, [...existing, file.name]);
|
|
74
|
+
}
|
|
75
|
+
const conflicts = [...names.entries()].filter(([, files]) => files.length > 1);
|
|
76
|
+
if (conflicts.length > 0) {
|
|
77
|
+
const messages = conflicts
|
|
78
|
+
.map(([name, files]) => `table "${name}" claimed by: ${files.join(", ")}`)
|
|
79
|
+
.join("\n");
|
|
80
|
+
throw E.migration_store_conflict(messages);
|
|
81
|
+
}
|
|
82
|
+
for (const store of migration_stores) {
|
|
83
|
+
const current = await store.db.schema.introspect(store.name, store.pk);
|
|
84
|
+
// table doesn't exist yet, create
|
|
85
|
+
if (current === null) {
|
|
86
|
+
diffs.push({
|
|
87
|
+
op: "create",
|
|
88
|
+
store,
|
|
89
|
+
});
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const db_fields = new Set(Object.keys(current));
|
|
93
|
+
const store_fields = new Set(Object.keys(store.types));
|
|
94
|
+
const add = Object.fromEntries([...store_fields]
|
|
95
|
+
.filter(f => !db_fields.has(f))
|
|
96
|
+
.map(f => [f, store.types[f]]));
|
|
97
|
+
const drop = [...db_fields].filter(f => !store_fields.has(f));
|
|
98
|
+
if (Object.keys(add).length === 0 && drop.length === 0)
|
|
99
|
+
continue;
|
|
100
|
+
diffs.push({
|
|
101
|
+
store,
|
|
102
|
+
op: "alter",
|
|
103
|
+
diff: { add, drop, rename: [] },
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
for (const diff_entry of diffs) {
|
|
107
|
+
if (diff_entry.op !== "alter")
|
|
108
|
+
continue;
|
|
109
|
+
const { diff, store } = diff_entry;
|
|
110
|
+
const current = await store.db.schema.introspect(store.name, store.pk);
|
|
111
|
+
const confirmed_renames = [];
|
|
112
|
+
const confirmed_drops = [];
|
|
113
|
+
for (const dropped of diff.drop) {
|
|
114
|
+
const candidates = current[dropped] ?? [];
|
|
115
|
+
const matching_added = Object.entries(diff.add)
|
|
116
|
+
.filter(([, type]) => candidates.includes(type))
|
|
117
|
+
.map(([name]) => name);
|
|
118
|
+
if (matching_added.length === 0) {
|
|
119
|
+
confirmed_drops.push(dropped);
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
for (const added of matching_added) {
|
|
123
|
+
const d = c.bold(dropped);
|
|
124
|
+
const a = c.bold(added);
|
|
125
|
+
const answer = await text({
|
|
126
|
+
message: `${d} was removed and ${a} was `
|
|
127
|
+
+ `added with a compatible type. Rename ${d} → ${a}? (y/N)`,
|
|
128
|
+
});
|
|
129
|
+
if (!is_cancel(answer) && answer.toLowerCase() === "y") {
|
|
130
|
+
confirmed_renames.push([dropped, added]);
|
|
131
|
+
delete diff.add[added];
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
confirmed_drops.push(dropped);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
diff.rename = confirmed_renames;
|
|
139
|
+
diff.drop = confirmed_drops;
|
|
140
|
+
}
|
|
141
|
+
if (diffs.length === 0) {
|
|
142
|
+
print("No schema changes detected.\n");
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if (!await migrations.exists())
|
|
146
|
+
await migrations.create();
|
|
147
|
+
const content = generate_migration(diffs);
|
|
148
|
+
const filename = `${next}-${string.toSlug(desc)}.ts`;
|
|
149
|
+
await migrations.join(filename).write(content);
|
|
150
|
+
print(`Created ${c.bold(`migrations/${filename}`)}.\n`);
|
|
151
|
+
process.exit();
|
|
152
|
+
}
|
|
153
|
+
;
|
|
154
|
+
//# sourceMappingURL=create.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import apply from "#db/migrate/apply";
|
|
2
|
+
import create from "#db/migrate/create";
|
|
3
|
+
import status from "#db/migrate/status";
|
|
4
|
+
declare const migrate: {
|
|
5
|
+
apply: typeof apply;
|
|
6
|
+
create: typeof create;
|
|
7
|
+
status: typeof status;
|
|
8
|
+
};
|
|
9
|
+
export default migrate;
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|