@gettersethya/mira 0.1.0-alpha.10
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 +21 -0
- package/README.md +103 -0
- package/dist/src/app/app.d.ts +100 -0
- package/dist/src/app/app.d.ts.map +1 -0
- package/dist/src/app/app.js +176 -0
- package/dist/src/app/app.js.map +1 -0
- package/dist/src/app/builder.d.ts +106 -0
- package/dist/src/app/builder.d.ts.map +1 -0
- package/dist/src/app/builder.js +122 -0
- package/dist/src/app/builder.js.map +1 -0
- package/dist/src/app/index.d.ts +33 -0
- package/dist/src/app/index.d.ts.map +1 -0
- package/dist/src/app/index.js +30 -0
- package/dist/src/app/index.js.map +1 -0
- package/dist/src/app/plugin.d.ts +60 -0
- package/dist/src/app/plugin.d.ts.map +1 -0
- package/dist/src/app/plugin.js +20 -0
- package/dist/src/app/plugin.js.map +1 -0
- package/dist/src/app/types.d.ts +55 -0
- package/dist/src/app/types.d.ts.map +1 -0
- package/dist/src/app/types.js +2 -0
- package/dist/src/app/types.js.map +1 -0
- package/dist/src/cache/cached-collection.d.ts +30 -0
- package/dist/src/cache/cached-collection.d.ts.map +1 -0
- package/dist/src/cache/cached-collection.js +107 -0
- package/dist/src/cache/cached-collection.js.map +1 -0
- package/dist/src/cache/collection-cache.d.ts +17 -0
- package/dist/src/cache/collection-cache.d.ts.map +1 -0
- package/dist/src/cache/collection-cache.js +37 -0
- package/dist/src/cache/collection-cache.js.map +1 -0
- package/dist/src/cache/index.d.ts +4 -0
- package/dist/src/cache/index.d.ts.map +1 -0
- package/dist/src/cache/index.js +3 -0
- package/dist/src/cache/index.js.map +1 -0
- package/dist/src/cache/types.d.ts +12 -0
- package/dist/src/cache/types.d.ts.map +1 -0
- package/dist/src/cache/types.js +2 -0
- package/dist/src/cache/types.js.map +1 -0
- package/dist/src/collection-service/collection-service.d.ts +62 -0
- package/dist/src/collection-service/collection-service.d.ts.map +1 -0
- package/dist/src/collection-service/collection-service.js +289 -0
- package/dist/src/collection-service/collection-service.js.map +1 -0
- package/dist/src/collection-service/context.d.ts +19 -0
- package/dist/src/collection-service/context.d.ts.map +1 -0
- package/dist/src/collection-service/context.js +2 -0
- package/dist/src/collection-service/context.js.map +1 -0
- package/dist/src/collection-service/decode.d.ts +6 -0
- package/dist/src/collection-service/decode.d.ts.map +1 -0
- package/dist/src/collection-service/decode.js +26 -0
- package/dist/src/collection-service/decode.js.map +1 -0
- package/dist/src/collection-service/errors.d.ts +67 -0
- package/dist/src/collection-service/errors.d.ts.map +1 -0
- package/dist/src/collection-service/errors.js +43 -0
- package/dist/src/collection-service/errors.js.map +1 -0
- package/dist/src/collection-service/index.d.ts +5 -0
- package/dist/src/collection-service/index.d.ts.map +1 -0
- package/dist/src/collection-service/index.js +3 -0
- package/dist/src/collection-service/index.js.map +1 -0
- package/dist/src/collection-service/input-schema.d.ts +10 -0
- package/dist/src/collection-service/input-schema.d.ts.map +1 -0
- package/dist/src/collection-service/input-schema.js +123 -0
- package/dist/src/collection-service/input-schema.js.map +1 -0
- package/dist/src/collection-service/where.d.ts +35 -0
- package/dist/src/collection-service/where.d.ts.map +1 -0
- package/dist/src/collection-service/where.js +91 -0
- package/dist/src/collection-service/where.js.map +1 -0
- package/dist/src/config/config.d.ts +44 -0
- package/dist/src/config/config.d.ts.map +1 -0
- package/dist/src/config/config.js +89 -0
- package/dist/src/config/config.js.map +1 -0
- package/dist/src/config/index.d.ts +3 -0
- package/dist/src/config/index.d.ts.map +1 -0
- package/dist/src/config/index.js +2 -0
- package/dist/src/config/index.js.map +1 -0
- package/dist/src/config/types.d.ts +29 -0
- package/dist/src/config/types.d.ts.map +1 -0
- package/dist/src/config/types.js +2 -0
- package/dist/src/config/types.js.map +1 -0
- package/dist/src/crypto/crypto.d.ts +11 -0
- package/dist/src/crypto/crypto.d.ts.map +1 -0
- package/dist/src/crypto/crypto.js +4 -0
- package/dist/src/crypto/crypto.js.map +1 -0
- package/dist/src/crypto/index.d.ts +3 -0
- package/dist/src/crypto/index.d.ts.map +1 -0
- package/dist/src/crypto/index.js +3 -0
- package/dist/src/crypto/index.js.map +1 -0
- package/dist/src/crypto/node.d.ts +4 -0
- package/dist/src/crypto/node.d.ts.map +1 -0
- package/dist/src/crypto/node.js +9 -0
- package/dist/src/crypto/node.js.map +1 -0
- package/dist/src/databases/index.d.ts +2 -0
- package/dist/src/databases/index.d.ts.map +1 -0
- package/dist/src/databases/index.js +2 -0
- package/dist/src/databases/index.js.map +1 -0
- package/dist/src/databases/sqlite.d.ts +24 -0
- package/dist/src/databases/sqlite.d.ts.map +1 -0
- package/dist/src/databases/sqlite.js +27 -0
- package/dist/src/databases/sqlite.js.map +1 -0
- package/dist/src/hooks/hook-collection.d.ts +5 -0
- package/dist/src/hooks/hook-collection.d.ts.map +1 -0
- package/dist/src/hooks/hook-collection.js +77 -0
- package/dist/src/hooks/hook-collection.js.map +1 -0
- package/dist/src/hooks/hook-service.d.ts +33 -0
- package/dist/src/hooks/hook-service.d.ts.map +1 -0
- package/dist/src/hooks/hook-service.js +118 -0
- package/dist/src/hooks/hook-service.js.map +1 -0
- package/dist/src/hooks/index.d.ts +4 -0
- package/dist/src/hooks/index.d.ts.map +1 -0
- package/dist/src/hooks/index.js +3 -0
- package/dist/src/hooks/index.js.map +1 -0
- package/dist/src/hooks/types.d.ts +52 -0
- package/dist/src/hooks/types.d.ts.map +1 -0
- package/dist/src/hooks/types.js +2 -0
- package/dist/src/hooks/types.js.map +1 -0
- package/dist/src/http/auth-node.d.ts +4 -0
- package/dist/src/http/auth-node.d.ts.map +1 -0
- package/dist/src/http/auth-node.js +34 -0
- package/dist/src/http/auth-node.js.map +1 -0
- package/dist/src/http/auth.d.ts +40 -0
- package/dist/src/http/auth.d.ts.map +1 -0
- package/dist/src/http/auth.js +76 -0
- package/dist/src/http/auth.js.map +1 -0
- package/dist/src/http/errors.d.ts +31 -0
- package/dist/src/http/errors.d.ts.map +1 -0
- package/dist/src/http/errors.js +36 -0
- package/dist/src/http/errors.js.map +1 -0
- package/dist/src/http/file-serve.d.ts +10 -0
- package/dist/src/http/file-serve.d.ts.map +1 -0
- package/dist/src/http/file-serve.js +159 -0
- package/dist/src/http/file-serve.js.map +1 -0
- package/dist/src/http/file-token.d.ts +7 -0
- package/dist/src/http/file-token.d.ts.map +1 -0
- package/dist/src/http/file-token.js +57 -0
- package/dist/src/http/file-token.js.map +1 -0
- package/dist/src/http/files.d.ts +11 -0
- package/dist/src/http/files.d.ts.map +1 -0
- package/dist/src/http/files.js +85 -0
- package/dist/src/http/files.js.map +1 -0
- package/dist/src/http/index.d.ts +11 -0
- package/dist/src/http/index.d.ts.map +1 -0
- package/dist/src/http/index.js +9 -0
- package/dist/src/http/index.js.map +1 -0
- package/dist/src/http/ip-middleware.d.ts +4 -0
- package/dist/src/http/ip-middleware.d.ts.map +1 -0
- package/dist/src/http/ip-middleware.js +24 -0
- package/dist/src/http/ip-middleware.js.map +1 -0
- package/dist/src/http/params.d.ts +15 -0
- package/dist/src/http/params.d.ts.map +1 -0
- package/dist/src/http/params.js +48 -0
- package/dist/src/http/params.js.map +1 -0
- package/dist/src/http/router.d.ts +11 -0
- package/dist/src/http/router.d.ts.map +1 -0
- package/dist/src/http/router.js +300 -0
- package/dist/src/http/router.js.map +1 -0
- package/dist/src/http/schema.d.ts +5 -0
- package/dist/src/http/schema.d.ts.map +1 -0
- package/dist/src/http/schema.js +17 -0
- package/dist/src/http/schema.js.map +1 -0
- package/dist/src/http/server-factory-node.d.ts +4 -0
- package/dist/src/http/server-factory-node.d.ts.map +1 -0
- package/dist/src/http/server-factory-node.js +8 -0
- package/dist/src/http/server-factory-node.js.map +1 -0
- package/dist/src/http/server-factory.d.ts +11 -0
- package/dist/src/http/server-factory.d.ts.map +1 -0
- package/dist/src/http/server-factory.js +4 -0
- package/dist/src/http/server-factory.js.map +1 -0
- package/dist/src/http/telemetry-routes.d.ts +5 -0
- package/dist/src/http/telemetry-routes.d.ts.map +1 -0
- package/dist/src/http/telemetry-routes.js +156 -0
- package/dist/src/http/telemetry-routes.js.map +1 -0
- package/dist/src/index.d.ts +19 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +22 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/migrator/dialect-sqlite.d.ts +9 -0
- package/dist/src/migrator/dialect-sqlite.d.ts.map +1 -0
- package/dist/src/migrator/dialect-sqlite.js +102 -0
- package/dist/src/migrator/dialect-sqlite.js.map +1 -0
- package/dist/src/migrator/dialect.d.ts +24 -0
- package/dist/src/migrator/dialect.d.ts.map +1 -0
- package/dist/src/migrator/dialect.js +5 -0
- package/dist/src/migrator/dialect.js.map +1 -0
- package/dist/src/migrator/index.d.ts +8 -0
- package/dist/src/migrator/index.d.ts.map +1 -0
- package/dist/src/migrator/index.js +6 -0
- package/dist/src/migrator/index.js.map +1 -0
- package/dist/src/migrator/migrator.d.ts +36 -0
- package/dist/src/migrator/migrator.d.ts.map +1 -0
- package/dist/src/migrator/migrator.js +200 -0
- package/dist/src/migrator/migrator.js.map +1 -0
- package/dist/src/migrator/schema-diff.d.ts +25 -0
- package/dist/src/migrator/schema-diff.d.ts.map +1 -0
- package/dist/src/migrator/schema-diff.js +157 -0
- package/dist/src/migrator/schema-diff.js.map +1 -0
- package/dist/src/migrator/types.d.ts +91 -0
- package/dist/src/migrator/types.d.ts.map +1 -0
- package/dist/src/migrator/types.js +13 -0
- package/dist/src/migrator/types.js.map +1 -0
- package/dist/src/platforms/node.d.ts +40 -0
- package/dist/src/platforms/node.d.ts.map +1 -0
- package/dist/src/platforms/node.js +45 -0
- package/dist/src/platforms/node.js.map +1 -0
- package/dist/src/repository/id.d.ts +5 -0
- package/dist/src/repository/id.d.ts.map +1 -0
- package/dist/src/repository/id.js +9 -0
- package/dist/src/repository/id.js.map +1 -0
- package/dist/src/repository/index.d.ts +3 -0
- package/dist/src/repository/index.d.ts.map +1 -0
- package/dist/src/repository/index.js +2 -0
- package/dist/src/repository/index.js.map +1 -0
- package/dist/src/repository/repository.d.ts +53 -0
- package/dist/src/repository/repository.d.ts.map +1 -0
- package/dist/src/repository/repository.js +150 -0
- package/dist/src/repository/repository.js.map +1 -0
- package/dist/src/repository/types.d.ts +42 -0
- package/dist/src/repository/types.d.ts.map +1 -0
- package/dist/src/repository/types.js +2 -0
- package/dist/src/repository/types.js.map +1 -0
- package/dist/src/rule/compiler.d.ts +52 -0
- package/dist/src/rule/compiler.d.ts.map +1 -0
- package/dist/src/rule/compiler.js +115 -0
- package/dist/src/rule/compiler.js.map +1 -0
- package/dist/src/rule/enforcer.d.ts +47 -0
- package/dist/src/rule/enforcer.d.ts.map +1 -0
- package/dist/src/rule/enforcer.js +60 -0
- package/dist/src/rule/enforcer.js.map +1 -0
- package/dist/src/rule/index.d.ts +3 -0
- package/dist/src/rule/index.d.ts.map +1 -0
- package/dist/src/rule/index.js +3 -0
- package/dist/src/rule/index.js.map +1 -0
- package/dist/src/storage/index.d.ts +3 -0
- package/dist/src/storage/index.d.ts.map +1 -0
- package/dist/src/storage/index.js +3 -0
- package/dist/src/storage/index.js.map +1 -0
- package/dist/src/storage/local-preset.d.ts +21 -0
- package/dist/src/storage/local-preset.d.ts.map +1 -0
- package/dist/src/storage/local-preset.js +21 -0
- package/dist/src/storage/local-preset.js.map +1 -0
- package/dist/src/storage/storage.d.ts +83 -0
- package/dist/src/storage/storage.d.ts.map +1 -0
- package/dist/src/storage/storage.js +120 -0
- package/dist/src/storage/storage.js.map +1 -0
- package/dist/src/telemetry/collections.d.ts +4 -0
- package/dist/src/telemetry/collections.d.ts.map +1 -0
- package/dist/src/telemetry/collections.js +19 -0
- package/dist/src/telemetry/collections.js.map +1 -0
- package/dist/src/telemetry/index.d.ts +9 -0
- package/dist/src/telemetry/index.d.ts.map +1 -0
- package/dist/src/telemetry/index.js +9 -0
- package/dist/src/telemetry/index.js.map +1 -0
- package/dist/src/telemetry/logger.d.ts +4 -0
- package/dist/src/telemetry/logger.d.ts.map +1 -0
- package/dist/src/telemetry/logger.js +27 -0
- package/dist/src/telemetry/logger.js.map +1 -0
- package/dist/src/telemetry/sqlite-logger.d.ts +24 -0
- package/dist/src/telemetry/sqlite-logger.d.ts.map +1 -0
- package/dist/src/telemetry/sqlite-logger.js +152 -0
- package/dist/src/telemetry/sqlite-logger.js.map +1 -0
- package/dist/src/telemetry/telemetry-sql-client.d.ts +11 -0
- package/dist/src/telemetry/telemetry-sql-client.d.ts.map +1 -0
- package/dist/src/telemetry/telemetry-sql-client.js +8 -0
- package/dist/src/telemetry/telemetry-sql-client.js.map +1 -0
- package/dist/src/telemetry/tracer.d.ts +16 -0
- package/dist/src/telemetry/tracer.d.ts.map +1 -0
- package/dist/src/telemetry/tracer.js +106 -0
- package/dist/src/telemetry/tracer.js.map +1 -0
- package/dist/src/thumbnail/index.d.ts +4 -0
- package/dist/src/thumbnail/index.d.ts.map +1 -0
- package/dist/src/thumbnail/index.js +3 -0
- package/dist/src/thumbnail/index.js.map +1 -0
- package/dist/src/thumbnail/photon.d.ts +9 -0
- package/dist/src/thumbnail/photon.d.ts.map +1 -0
- package/dist/src/thumbnail/photon.js +73 -0
- package/dist/src/thumbnail/photon.js.map +1 -0
- package/dist/src/thumbnail/types.d.ts +23 -0
- package/dist/src/thumbnail/types.d.ts.map +1 -0
- package/dist/src/thumbnail/types.js +22 -0
- package/dist/src/thumbnail/types.js.map +1 -0
- package/dist/tests/app/app.test.d.ts +2 -0
- package/dist/tests/app/app.test.d.ts.map +1 -0
- package/dist/tests/app/app.test.js +125 -0
- package/dist/tests/app/app.test.js.map +1 -0
- package/dist/tests/app/builder.test.d.ts +2 -0
- package/dist/tests/app/builder.test.d.ts.map +1 -0
- package/dist/tests/app/builder.test.js +70 -0
- package/dist/tests/app/builder.test.js.map +1 -0
- package/dist/tests/cache/cached-collection.test.d.ts +2 -0
- package/dist/tests/cache/cached-collection.test.d.ts.map +1 -0
- package/dist/tests/cache/cached-collection.test.js +244 -0
- package/dist/tests/cache/cached-collection.test.js.map +1 -0
- package/dist/tests/cache/collection-cache.test.d.ts +2 -0
- package/dist/tests/cache/collection-cache.test.d.ts.map +1 -0
- package/dist/tests/cache/collection-cache.test.js +73 -0
- package/dist/tests/cache/collection-cache.test.js.map +1 -0
- package/dist/tests/collection-service/collection-service.test.d.ts +2 -0
- package/dist/tests/collection-service/collection-service.test.d.ts.map +1 -0
- package/dist/tests/collection-service/collection-service.test.js +938 -0
- package/dist/tests/collection-service/collection-service.test.js.map +1 -0
- package/dist/tests/collection-service/input-schema.test.d.ts +2 -0
- package/dist/tests/collection-service/input-schema.test.d.ts.map +1 -0
- package/dist/tests/collection-service/input-schema.test.js +327 -0
- package/dist/tests/collection-service/input-schema.test.js.map +1 -0
- package/dist/tests/config/config.test.d.ts +2 -0
- package/dist/tests/config/config.test.d.ts.map +1 -0
- package/dist/tests/config/config.test.js +84 -0
- package/dist/tests/config/config.test.js.map +1 -0
- package/dist/tests/crypto/crypto.test.d.ts +2 -0
- package/dist/tests/crypto/crypto.test.d.ts.map +1 -0
- package/dist/tests/crypto/crypto.test.js +56 -0
- package/dist/tests/crypto/crypto.test.js.map +1 -0
- package/dist/tests/hooks/hook-collection.test.d.ts +2 -0
- package/dist/tests/hooks/hook-collection.test.d.ts.map +1 -0
- package/dist/tests/hooks/hook-collection.test.js +103 -0
- package/dist/tests/hooks/hook-collection.test.js.map +1 -0
- package/dist/tests/hooks/hook-service.test.d.ts +2 -0
- package/dist/tests/hooks/hook-service.test.d.ts.map +1 -0
- package/dist/tests/hooks/hook-service.test.js +216 -0
- package/dist/tests/hooks/hook-service.test.js.map +1 -0
- package/dist/tests/http/file-serve.test.d.ts +2 -0
- package/dist/tests/http/file-serve.test.d.ts.map +1 -0
- package/dist/tests/http/file-serve.test.js +210 -0
- package/dist/tests/http/file-serve.test.js.map +1 -0
- package/dist/tests/http/file-token.test.d.ts +2 -0
- package/dist/tests/http/file-token.test.d.ts.map +1 -0
- package/dist/tests/http/file-token.test.js +165 -0
- package/dist/tests/http/file-token.test.js.map +1 -0
- package/dist/tests/http/ip-middleware.test.d.ts +2 -0
- package/dist/tests/http/ip-middleware.test.d.ts.map +1 -0
- package/dist/tests/http/ip-middleware.test.js +58 -0
- package/dist/tests/http/ip-middleware.test.js.map +1 -0
- package/dist/tests/http/router.test.d.ts +2 -0
- package/dist/tests/http/router.test.d.ts.map +1 -0
- package/dist/tests/http/router.test.js +312 -0
- package/dist/tests/http/router.test.js.map +1 -0
- package/dist/tests/migrator/dialect-sqlite.test.d.ts +2 -0
- package/dist/tests/migrator/dialect-sqlite.test.d.ts.map +1 -0
- package/dist/tests/migrator/dialect-sqlite.test.js +90 -0
- package/dist/tests/migrator/dialect-sqlite.test.js.map +1 -0
- package/dist/tests/migrator/integration.test.d.ts +2 -0
- package/dist/tests/migrator/integration.test.d.ts.map +1 -0
- package/dist/tests/migrator/integration.test.js +180 -0
- package/dist/tests/migrator/integration.test.js.map +1 -0
- package/dist/tests/migrator/migrator.test.d.ts +2 -0
- package/dist/tests/migrator/migrator.test.d.ts.map +1 -0
- package/dist/tests/migrator/migrator.test.js +225 -0
- package/dist/tests/migrator/migrator.test.js.map +1 -0
- package/dist/tests/migrator/schema-diff.test.d.ts +2 -0
- package/dist/tests/migrator/schema-diff.test.d.ts.map +1 -0
- package/dist/tests/migrator/schema-diff.test.js +323 -0
- package/dist/tests/migrator/schema-diff.test.js.map +1 -0
- package/dist/tests/repository/repository.test.d.ts +2 -0
- package/dist/tests/repository/repository.test.d.ts.map +1 -0
- package/dist/tests/repository/repository.test.js +255 -0
- package/dist/tests/repository/repository.test.js.map +1 -0
- package/dist/tests/rule/compiler.test.d.ts +2 -0
- package/dist/tests/rule/compiler.test.d.ts.map +1 -0
- package/dist/tests/rule/compiler.test.js +226 -0
- package/dist/tests/rule/compiler.test.js.map +1 -0
- package/dist/tests/rule/enforcer.test.d.ts +2 -0
- package/dist/tests/rule/enforcer.test.d.ts.map +1 -0
- package/dist/tests/rule/enforcer.test.js +190 -0
- package/dist/tests/rule/enforcer.test.js.map +1 -0
- package/dist/tests/storage/storage.test.d.ts +2 -0
- package/dist/tests/storage/storage.test.d.ts.map +1 -0
- package/dist/tests/storage/storage.test.js +76 -0
- package/dist/tests/storage/storage.test.js.map +1 -0
- package/dist/tests/telemetry/collections.test.d.ts +2 -0
- package/dist/tests/telemetry/collections.test.d.ts.map +1 -0
- package/dist/tests/telemetry/collections.test.js +67 -0
- package/dist/tests/telemetry/collections.test.js.map +1 -0
- package/dist/tests/telemetry/instrumentation.test.d.ts +2 -0
- package/dist/tests/telemetry/instrumentation.test.d.ts.map +1 -0
- package/dist/tests/telemetry/instrumentation.test.js +226 -0
- package/dist/tests/telemetry/instrumentation.test.js.map +1 -0
- package/dist/tests/telemetry/logger.test.d.ts +2 -0
- package/dist/tests/telemetry/logger.test.d.ts.map +1 -0
- package/dist/tests/telemetry/logger.test.js +56 -0
- package/dist/tests/telemetry/logger.test.js.map +1 -0
- package/dist/tests/telemetry/sqlite-logger.test.d.ts +2 -0
- package/dist/tests/telemetry/sqlite-logger.test.d.ts.map +1 -0
- package/dist/tests/telemetry/sqlite-logger.test.js +218 -0
- package/dist/tests/telemetry/sqlite-logger.test.js.map +1 -0
- package/dist/tests/telemetry/telemetry-routes.test.d.ts +2 -0
- package/dist/tests/telemetry/telemetry-routes.test.d.ts.map +1 -0
- package/dist/tests/telemetry/telemetry-routes.test.js +133 -0
- package/dist/tests/telemetry/telemetry-routes.test.js.map +1 -0
- package/dist/tests/telemetry/tracer.test.d.ts +2 -0
- package/dist/tests/telemetry/tracer.test.d.ts.map +1 -0
- package/dist/tests/telemetry/tracer.test.js +63 -0
- package/dist/tests/telemetry/tracer.test.js.map +1 -0
- package/dist/tests/thumbnail/photon.test.d.ts +2 -0
- package/dist/tests/thumbnail/photon.test.d.ts.map +1 -0
- package/dist/tests/thumbnail/photon.test.js +478 -0
- package/dist/tests/thumbnail/photon.test.js.map +1 -0
- package/dist/tests/thumbnail/thumbnail.test.d.ts +2 -0
- package/dist/tests/thumbnail/thumbnail.test.d.ts.map +1 -0
- package/dist/tests/thumbnail/thumbnail.test.js +35 -0
- package/dist/tests/thumbnail/thumbnail.test.js.map +1 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Getter Sethya
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# @gettersethya/mira
|
|
2
|
+
|
|
3
|
+
> **Early pre-alpha.** Breaking changes may occur without notice.
|
|
4
|
+
|
|
5
|
+
Self-hosted backend in TypeScript using [Effect](https://effect.website). Define collections, get a full REST API with auth, file storage, access rules, and schema migrations — all with zero config.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @gettersethya/mira @gettersethya/mira-collection effect
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @gettersethya/mira @gettersethya/mira-collection effect
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick start
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { LocalFileStorage, Mira, NodePlatform, SqliteDatabase } from "@gettersethya/mira"
|
|
19
|
+
import { Posts, Users } from "./collections.js"
|
|
20
|
+
|
|
21
|
+
const app = Mira.builder()
|
|
22
|
+
.platform(NodePlatform)
|
|
23
|
+
.database(SqliteDatabase({ filename: "mira.db" }))
|
|
24
|
+
.storage(LocalFileStorage({ directory: "./uploads" }))
|
|
25
|
+
.collections([Users, Posts])
|
|
26
|
+
.build()
|
|
27
|
+
|
|
28
|
+
app.serve({ port: 3000 })
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The builder uses phantom types to enforce step ordering — TypeScript will not let you call `.build()` until all four steps are complete.
|
|
32
|
+
|
|
33
|
+
On first boot, Mira auto-generates a `jwt_secret`, runs schema migrations, and creates SQL views for view collections. Everything is persisted in the database.
|
|
34
|
+
|
|
35
|
+
## Builder steps
|
|
36
|
+
|
|
37
|
+
| Step | Required | Description |
|
|
38
|
+
|---|---|---|
|
|
39
|
+
| `.platform(p)` | Yes | Runtime environment (Node.js, etc.) |
|
|
40
|
+
| `.database(d)` | Yes | Database backend |
|
|
41
|
+
| `.storage(s)` | Yes | File storage backend |
|
|
42
|
+
| `.collections(c)` | Yes | Collection definitions |
|
|
43
|
+
| `.telemetry(layer)` | No | Custom Effect telemetry layer |
|
|
44
|
+
| `.extend(layer)` | No | Inject additional layers before serving |
|
|
45
|
+
|
|
46
|
+
## Platforms
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import { NodePlatform } from "@gettersethya/mira"
|
|
50
|
+
|
|
51
|
+
// Provides: CryptoService, FileSystem, HttpServerFactory, AuthService
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Databases
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import { SqliteDatabase } from "@gettersethya/mira"
|
|
58
|
+
|
|
59
|
+
SqliteDatabase({ filename: "mira.db" })
|
|
60
|
+
SqliteDatabase({ filename: ":memory:" }) // in-memory for tests
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Storage
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import { LocalFileStorage } from "@gettersethya/mira"
|
|
67
|
+
|
|
68
|
+
LocalFileStorage({ directory: "./uploads" })
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Auto-generated endpoints
|
|
72
|
+
|
|
73
|
+
Each collection gets a full set of REST endpoints:
|
|
74
|
+
|
|
75
|
+
| Method | Path | Description |
|
|
76
|
+
|---|---|---|
|
|
77
|
+
| `GET` | `/api/:collection` | List (filter, sort, cursor, expand, select) |
|
|
78
|
+
| `GET` | `/api/:collection/:id` | Get one |
|
|
79
|
+
| `POST` | `/api/:collection` | Create |
|
|
80
|
+
| `PATCH` | `/api/:collection/:id` | Update |
|
|
81
|
+
| `DELETE` | `/api/:collection/:id` | Delete |
|
|
82
|
+
| `POST` | `/api/:collection/authWithPassword` | Login (auth collections only) |
|
|
83
|
+
| `POST` | `/api/auth/logout` | Logout |
|
|
84
|
+
| `POST` | `/api/files/token` | Request protected file token |
|
|
85
|
+
| `GET` | `/api/files/:collection/:id/:filename` | Serve file |
|
|
86
|
+
|
|
87
|
+
## Testing with the service layer
|
|
88
|
+
|
|
89
|
+
Use `.buildServiceLayer()` to get an Effect `Layer` for all services without starting an HTTP server:
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
import { Effect, Layer } from "effect"
|
|
93
|
+
|
|
94
|
+
const serviceLayer = app.buildServiceLayer()
|
|
95
|
+
|
|
96
|
+
const test = Effect.gen(function* () {
|
|
97
|
+
// inject and use services directly
|
|
98
|
+
}).pipe(Effect.provide(serviceLayer))
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## More
|
|
102
|
+
|
|
103
|
+
See the [Mira root README](https://github.com/gettersethya/mira) for collection definitions, field types, rules, filter DSL, and client usage.
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { HttpServer } from "@effect/platform";
|
|
2
|
+
import { Layer } from "effect";
|
|
3
|
+
import { Migrator } from "../migrator/migrator.js";
|
|
4
|
+
import { AppConfig } from "../config/index.js";
|
|
5
|
+
import type { Repository } from "../repository/index.js";
|
|
6
|
+
import type { CollectionService } from "../collection-service/collection-service.js";
|
|
7
|
+
import type { MiraAppConfig } from "./builder.js";
|
|
8
|
+
import type { MiraPlugin } from "./plugin.js";
|
|
9
|
+
/**
|
|
10
|
+
* The assembled Mira application, ready to serve.
|
|
11
|
+
*
|
|
12
|
+
* Created by `MiraBuilder.build()`. Do not construct directly — use the
|
|
13
|
+
* `Mira.builder()` fluent API.
|
|
14
|
+
*
|
|
15
|
+
* `MiraApp` wires all layers (database, storage, collection service, HTTP server,
|
|
16
|
+
* telemetry, auto-migration) and provides `serve()` to start the server.
|
|
17
|
+
* Use `extend()` to add plugins before serving.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const app = Mira.builder()
|
|
21
|
+
* .platform(NodePlatform)
|
|
22
|
+
* .database(SqliteDatabase({ filename: "data.db" }))
|
|
23
|
+
* .storage(LocalFileStorage({ directory: "./uploads" }))
|
|
24
|
+
* .collections([Posts, Users])
|
|
25
|
+
* .build()
|
|
26
|
+
*
|
|
27
|
+
* app.serve()
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* // With plugin
|
|
31
|
+
* app.extend(MiraDashboard).serve({ port: 8080 })
|
|
32
|
+
*
|
|
33
|
+
* @see MiraBuilder — builds MiraApp
|
|
34
|
+
* @see Mira — entry point: Mira.builder()
|
|
35
|
+
*/
|
|
36
|
+
export declare class MiraApp {
|
|
37
|
+
#private;
|
|
38
|
+
constructor(config: MiraAppConfig);
|
|
39
|
+
/** @internal for tests only */
|
|
40
|
+
_getConfig(): MiraAppConfig;
|
|
41
|
+
/** @internal for tests only */
|
|
42
|
+
_getExtras(): ReadonlyArray<MiraPlugin>;
|
|
43
|
+
/**
|
|
44
|
+
* Add a plugin to the application. Plugins can register lifecycle hooks,
|
|
45
|
+
* record-lifecycle hooks, custom routes, service layers, and additional
|
|
46
|
+
* collection definitions.
|
|
47
|
+
*
|
|
48
|
+
* @param plugin - A MiraPlugin (use `fromLayer()` to wrap a plain Layer)
|
|
49
|
+
* @returns this (for chaining)
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* app.extend(MiraDashboard).serve()
|
|
53
|
+
*/
|
|
54
|
+
extend(plugin: MiraPlugin): this;
|
|
55
|
+
/**
|
|
56
|
+
* Build the full service layer without the HTTP server.
|
|
57
|
+
* Useful for testing — you can run Effects against the service layer without
|
|
58
|
+
* starting a network server.
|
|
59
|
+
*
|
|
60
|
+
* Includes: database, storage, telemetry, repository, migrator, app config,
|
|
61
|
+
* collection service (with cache + hooks), and auto-migration.
|
|
62
|
+
*
|
|
63
|
+
* @returns A Layer providing all services
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* const serviceLayer = app.buildServiceLayer()
|
|
67
|
+
* const result = await Effect.runPromise(
|
|
68
|
+
* Effect.gen(function* () { ... }).pipe(Effect.provide(serviceLayer))
|
|
69
|
+
* )
|
|
70
|
+
*/
|
|
71
|
+
buildServiceLayer(): Layer.Layer<Migrator | import("../index.js").FileStorage | import("./types.js").PlatformServices | import("./types.js").DatabaseServices | Repository | CollectionService | import("../thumbnail/index.js").ThumbnailService | AppConfig, import("effect/ParseResult").ParseError | import("@effect/sql/SqlError").SqlError, CollectionService>;
|
|
72
|
+
/**
|
|
73
|
+
* Build the complete server layer including the HTTP router and server.
|
|
74
|
+
* Accepts an optional port override (otherwise uses the port from AppConfig).
|
|
75
|
+
*
|
|
76
|
+
* @param options.port - Optional port number override
|
|
77
|
+
* @returns A Layer ready to be launched
|
|
78
|
+
*
|
|
79
|
+
* @internal Called by serve() — most users should use serve() directly.
|
|
80
|
+
*/
|
|
81
|
+
buildLayer(options?: {
|
|
82
|
+
port?: number;
|
|
83
|
+
}): Layer.Layer<Migrator | HttpServer.HttpServer | import("@effect/platform/HttpPlatform").HttpPlatform | import("@effect/platform/Etag").Generator | import("../index.js").FileStorage | import("./types.js").PlatformServices | import("./types.js").DatabaseServices | Repository | CollectionService | import("../thumbnail/index.js").ThumbnailService | AppConfig, import("effect/ParseResult").ParseError | import("@effect/sql/SqlError").SqlError | import("@effect/platform/HttpServerError").ServeError, CollectionService>;
|
|
84
|
+
/**
|
|
85
|
+
* Start the Mira HTTP server.
|
|
86
|
+
* Sets up all services, runs auto-migration, runs plugin lifecycle hooks,
|
|
87
|
+
* and listens for incoming requests.
|
|
88
|
+
* Blocks the main thread until the server is shut down.
|
|
89
|
+
*
|
|
90
|
+
* @param options.port - Optional port override (default: from AppConfig, typically 8080)
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* app.serve() // default port
|
|
94
|
+
* app.serve({ port: 8080 }) // port override
|
|
95
|
+
*/
|
|
96
|
+
serve(options?: {
|
|
97
|
+
port?: number;
|
|
98
|
+
}): void;
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=app.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../../src/app/app.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,UAAU,EAAQ,MAAM,kBAAkB,CAAA;AAE3E,OAAO,EAAU,KAAK,EAAE,MAAM,QAAQ,CAAA;AAEtC,OAAO,EAAE,QAAQ,EAAgB,MAAM,wBAAwB,CAAA;AAM/D,OAAO,EAAE,SAAS,EAAiB,MAAM,mBAAmB,CAAA;AAG5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4CAA4C,CAAA;AAEnF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAK7C;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,OAAO;;gBAIN,MAAM,EAAE,aAAa;IAKjC,+BAA+B;IAC/B,UAAU,IAAI,aAAa;IAI3B,+BAA+B;IAC/B,UAAU,IAAI,aAAa,CAAC,UAAU,CAAC;IAIvC;;;;;;;;;;OAUG;IACH,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAgBhC;;;;;;;;;;;;;;;OAeG;IACH,iBAAiB;IAgDjB;;;;;;;;OAQG;IACH,UAAU,CAAC,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE;IAgCtC;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;CAczC"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { HttpRouter, HttpServer } from "@effect/platform";
|
|
2
|
+
import { Effect, Layer } from "effect";
|
|
3
|
+
import { RepositoryLive } from "../repository/repository.js";
|
|
4
|
+
import { Migrator, MigratorLive } from "../migrator/migrator.js";
|
|
5
|
+
import { makeCachedCollectionServiceLayer } from "../cache/index.js";
|
|
6
|
+
import { makeCollectionRouter } from "../http/router.js";
|
|
7
|
+
import { ThumbnailServicePhotonLive } from "../thumbnail/index.js";
|
|
8
|
+
import { ipAnnotationMiddleware } from "../http/ip-middleware.js";
|
|
9
|
+
import { AppConfig, AppConfigLive } from "../config/index.js";
|
|
10
|
+
import { HttpServerFactory } from "../http/server-factory.js";
|
|
11
|
+
import { makeHookServiceLayer } from "../hooks/hook-service.js";
|
|
12
|
+
import { makeHookCollectionServiceLayer } from "../hooks/hook-collection.js";
|
|
13
|
+
import { HookService } from "../hooks/hook-service.js";
|
|
14
|
+
/**
|
|
15
|
+
* The assembled Mira application, ready to serve.
|
|
16
|
+
*
|
|
17
|
+
* Created by `MiraBuilder.build()`. Do not construct directly — use the
|
|
18
|
+
* `Mira.builder()` fluent API.
|
|
19
|
+
*
|
|
20
|
+
* `MiraApp` wires all layers (database, storage, collection service, HTTP server,
|
|
21
|
+
* telemetry, auto-migration) and provides `serve()` to start the server.
|
|
22
|
+
* Use `extend()` to add plugins before serving.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* const app = Mira.builder()
|
|
26
|
+
* .platform(NodePlatform)
|
|
27
|
+
* .database(SqliteDatabase({ filename: "data.db" }))
|
|
28
|
+
* .storage(LocalFileStorage({ directory: "./uploads" }))
|
|
29
|
+
* .collections([Posts, Users])
|
|
30
|
+
* .build()
|
|
31
|
+
*
|
|
32
|
+
* app.serve()
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* // With plugin
|
|
36
|
+
* app.extend(MiraDashboard).serve({ port: 8080 })
|
|
37
|
+
*
|
|
38
|
+
* @see MiraBuilder — builds MiraApp
|
|
39
|
+
* @see Mira — entry point: Mira.builder()
|
|
40
|
+
*/
|
|
41
|
+
export class MiraApp {
|
|
42
|
+
#config;
|
|
43
|
+
#extras;
|
|
44
|
+
constructor(config) {
|
|
45
|
+
this.#config = config;
|
|
46
|
+
this.#extras = [];
|
|
47
|
+
}
|
|
48
|
+
/** @internal for tests only */
|
|
49
|
+
_getConfig() {
|
|
50
|
+
return this.#config;
|
|
51
|
+
}
|
|
52
|
+
/** @internal for tests only */
|
|
53
|
+
_getExtras() {
|
|
54
|
+
return this.#extras;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Add a plugin to the application. Plugins can register lifecycle hooks,
|
|
58
|
+
* record-lifecycle hooks, custom routes, service layers, and additional
|
|
59
|
+
* collection definitions.
|
|
60
|
+
*
|
|
61
|
+
* @param plugin - A MiraPlugin (use `fromLayer()` to wrap a plain Layer)
|
|
62
|
+
* @returns this (for chaining)
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* app.extend(MiraDashboard).serve()
|
|
66
|
+
*/
|
|
67
|
+
extend(plugin) {
|
|
68
|
+
this.#extras.push(plugin);
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
#getAllCollections() {
|
|
72
|
+
return [
|
|
73
|
+
...this.#config.collections,
|
|
74
|
+
...this.#extras.flatMap((p) => p.collections ?? [])
|
|
75
|
+
];
|
|
76
|
+
}
|
|
77
|
+
#getAllPlugins() {
|
|
78
|
+
return this.#extras;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Build the full service layer without the HTTP server.
|
|
82
|
+
* Useful for testing — you can run Effects against the service layer without
|
|
83
|
+
* starting a network server.
|
|
84
|
+
*
|
|
85
|
+
* Includes: database, storage, telemetry, repository, migrator, app config,
|
|
86
|
+
* collection service (with cache + hooks), and auto-migration.
|
|
87
|
+
*
|
|
88
|
+
* @returns A Layer providing all services
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* const serviceLayer = app.buildServiceLayer()
|
|
92
|
+
* const result = await Effect.runPromise(
|
|
93
|
+
* Effect.gen(function* () { ... }).pipe(Effect.provide(serviceLayer))
|
|
94
|
+
* )
|
|
95
|
+
*/
|
|
96
|
+
buildServiceLayer() {
|
|
97
|
+
const { platform, database, storage, telemetry } = this.#config;
|
|
98
|
+
const allCollections = this.#getAllCollections();
|
|
99
|
+
const allPlugins = this.#getAllPlugins();
|
|
100
|
+
const pluginLayers = allPlugins.filter((p) => p.layer !== undefined).map((p) => p.layer);
|
|
101
|
+
const extrasLayer = pluginLayers.length > 0 ? pluginLayers.reduce((acc, l) => Layer.merge(acc, l)) : Layer.empty;
|
|
102
|
+
// Foundation: database + storage + thumbnail + telemetry, wired on platform
|
|
103
|
+
const foundation = Layer.mergeAll(database.layer, storage.layer, ThumbnailServicePhotonLive, telemetry).pipe(Layer.provideMerge(platform.layer));
|
|
104
|
+
// Mid: Repository + Migrator + AppConfig, wired on foundation
|
|
105
|
+
const mid = Layer.mergeAll(RepositoryLive, MigratorLive, AppConfigLive).pipe(Layer.provideMerge(foundation));
|
|
106
|
+
// Extras: plugin layers run after mid so they can depend on AppConfig + platform services
|
|
107
|
+
const extrasProvided = extrasLayer.pipe(Layer.provide(mid));
|
|
108
|
+
const fullMid = Layer.merge(mid, extrasProvided);
|
|
109
|
+
// Auto-migrate on boot: runs during layer initialization before requests are served
|
|
110
|
+
const schemas = allCollections.map((c) => ({ name: c.name, schema: c.schema }));
|
|
111
|
+
const autoMigrateLayer = Layer.effectDiscard(Effect.gen(function* () {
|
|
112
|
+
const migrator = yield* Migrator;
|
|
113
|
+
yield* migrator.migrate(schemas);
|
|
114
|
+
}).pipe(Effect.orDie)).pipe(Layer.provide(fullMid));
|
|
115
|
+
// Core collection service (cached)
|
|
116
|
+
const cachedCollectionLayer = makeCachedCollectionServiceLayer(allCollections);
|
|
117
|
+
// Hook service layer (collects all plugin hooks)
|
|
118
|
+
const hookServiceLayer = makeHookServiceLayer(allPlugins);
|
|
119
|
+
// Hook collection service decorator: wraps cached collection service with hooks
|
|
120
|
+
const hookCollectionLayer = makeHookCollectionServiceLayer().pipe(Layer.provide(Layer.mergeAll(cachedCollectionLayer, hookServiceLayer)));
|
|
121
|
+
// Top: hook-wrapped collection service + all mid services + auto-migration side effect
|
|
122
|
+
return hookCollectionLayer.pipe(Layer.provideMerge(Layer.merge(fullMid, autoMigrateLayer)));
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Build the complete server layer including the HTTP router and server.
|
|
126
|
+
* Accepts an optional port override (otherwise uses the port from AppConfig).
|
|
127
|
+
*
|
|
128
|
+
* @param options.port - Optional port number override
|
|
129
|
+
* @returns A Layer ready to be launched
|
|
130
|
+
*
|
|
131
|
+
* @internal Called by serve() — most users should use serve() directly.
|
|
132
|
+
*/
|
|
133
|
+
buildLayer(options) {
|
|
134
|
+
const allCollections = this.#getAllCollections();
|
|
135
|
+
const collectionRouter = makeCollectionRouter(allCollections);
|
|
136
|
+
// Plugin routes
|
|
137
|
+
let pluginRouter = HttpRouter.empty;
|
|
138
|
+
for (const plugin of this.#extras) {
|
|
139
|
+
if (plugin.routes !== undefined) {
|
|
140
|
+
pluginRouter = HttpRouter.concat(pluginRouter, plugin.routes);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
const router = HttpRouter.concat(collectionRouter, pluginRouter);
|
|
144
|
+
const serviceLayer = this.buildServiceLayer();
|
|
145
|
+
const serverLayer = Layer.unwrapEffect(Effect.gen(function* () {
|
|
146
|
+
const cfg = yield* AppConfig;
|
|
147
|
+
const factory = yield* HttpServerFactory;
|
|
148
|
+
return factory.makeLayer(options?.port ?? cfg.port);
|
|
149
|
+
}));
|
|
150
|
+
return HttpServer.serve(ipAnnotationMiddleware(router)).pipe(Layer.provideMerge(serverLayer), Layer.provideMerge(serviceLayer));
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Start the Mira HTTP server.
|
|
154
|
+
* Sets up all services, runs auto-migration, runs plugin lifecycle hooks,
|
|
155
|
+
* and listens for incoming requests.
|
|
156
|
+
* Blocks the main thread until the server is shut down.
|
|
157
|
+
*
|
|
158
|
+
* @param options.port - Optional port override (default: from AppConfig, typically 8080)
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* app.serve() // default port
|
|
162
|
+
* app.serve({ port: 8080 }) // port override
|
|
163
|
+
*/
|
|
164
|
+
serve(options) {
|
|
165
|
+
const allPlugins = this.#getAllPlugins();
|
|
166
|
+
const hookServiceLayer = makeHookServiceLayer(allPlugins);
|
|
167
|
+
const fullLayer = this.buildLayer(options);
|
|
168
|
+
this.#config.platform.runMain(Effect.gen(this, function* () {
|
|
169
|
+
const hookService = yield* HookService.pipe(Effect.provide(hookServiceLayer));
|
|
170
|
+
const bootstrapLayer = Layer.effectDiscard(hookService.runBootstrap());
|
|
171
|
+
yield* Layer.launch(bootstrapLayer.pipe(Layer.provideMerge(fullLayer)));
|
|
172
|
+
yield* hookService.runServe();
|
|
173
|
+
}));
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=app.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../../../src/app/app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,UAAU,EAAE,UAAU,EAAQ,MAAM,kBAAkB,CAAA;AAE3E,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAE/D,OAAO,EAAE,gCAAgC,EAAE,MAAM,kBAAkB,CAAA;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAA;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAA;AAChE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAE5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAM5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,EAAE,8BAA8B,EAAE,MAAM,4BAA4B,CAAA;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAErD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,OAAO,OAAO;IACT,OAAO,CAAe;IACtB,OAAO,CAAmB;IAEnC,YAAY,MAAqB;QAC/B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;QACrB,IAAI,CAAC,OAAO,GAAG,EAAE,CAAA;IACnB,CAAC;IAED,+BAA+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ACrD,CAAC,CAAC,CACH,CAAA;QAED,OAAO,UAAU,CAAC,KAAK,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAC1D,KAAK,CAAC,YAAY,CAAC,WAAW,CAAC,EAC/B,KAAK,CAAC,YAAY,CAAC,YAAY,CAAC,CACjC,CAAA;IACH,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,OAA2B;QAC/B,MAAM,UAAU,GAAG,IAAI,CAAC,cAAc,EAAE,CAAA;QACxC,MAAM,gBAAgB,GAAG,oBAAoB,CAAC,UAAU,CAAC,CAAA;QACzD,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;QAE1C,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAC3B,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC;YACxB,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAA;YAC7E,MAAM,cAAc,GAAG,KAAK,CAAC,aAAa,CAAC,WAAW,CAAC,YAAY,EAAE,CAAC,CAAA;YACtE,KAAK,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;YACvE,KAAK,CAAC,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAA;QAC/B,CAAC,CAAuC,CACzC,CAAA;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { Layer } from "effect";
|
|
2
|
+
import type { AnyCollectionDef } from "@gettersethya/mira-client";
|
|
3
|
+
import type { MiraPlatform, MiraDatabase, MiraStorage } from "./types.js";
|
|
4
|
+
import { MiraApp } from "./app.js";
|
|
5
|
+
/**
|
|
6
|
+
* Configuration object for `MiraApp`. Constructed by `MiraBuilder` after all
|
|
7
|
+
* required steps are called. Only the `telemetry` field is optional — it defaults
|
|
8
|
+
* to `ConsoleTelemetryLayer`.
|
|
9
|
+
*
|
|
10
|
+
* @see MiraBuilder — builds this config
|
|
11
|
+
*/
|
|
12
|
+
export interface MiraAppConfig {
|
|
13
|
+
platform: MiraPlatform;
|
|
14
|
+
database: MiraDatabase;
|
|
15
|
+
storage: MiraStorage;
|
|
16
|
+
collections: ReadonlyArray<AnyCollectionDef>;
|
|
17
|
+
telemetry: Layer.Layer<never, never, never>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Phantom-type builder for constructing a `MiraApp`.
|
|
21
|
+
*
|
|
22
|
+
* Uses TypeScript's type system to enforce that all required steps are called
|
|
23
|
+
* before `build()` is allowed. The type parameter `Has` tracks which steps have
|
|
24
|
+
* been completed.
|
|
25
|
+
*
|
|
26
|
+
* Required steps (order does not matter):
|
|
27
|
+
* 1. `.platform(p)` — choose Node, Bun, etc.
|
|
28
|
+
* 2. `.database(d)` — choose SQLite, etc.
|
|
29
|
+
* 3. `.storage(s)` — choose LocalFileStorage, S3, etc.
|
|
30
|
+
* 4. `.collections(c)` — provide collection definitions
|
|
31
|
+
*
|
|
32
|
+
* Optional step: `.telemetry(l)` — custom telemetry layer
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* const app = Mira.builder()
|
|
36
|
+
* .platform(NodePlatform)
|
|
37
|
+
* .database(SqliteDatabase({ filename: "data.db" }))
|
|
38
|
+
* .storage(LocalFileStorage({ directory: "./uploads" }))
|
|
39
|
+
* .collections([Posts, Users])
|
|
40
|
+
* .build()
|
|
41
|
+
* .serve()
|
|
42
|
+
*
|
|
43
|
+
* @see MiraApp — the assembled application
|
|
44
|
+
* @see Mira.builder — entry point
|
|
45
|
+
*/
|
|
46
|
+
export declare class MiraBuilder<Has extends string = never> {
|
|
47
|
+
#private;
|
|
48
|
+
constructor(config?: Partial<MiraAppConfig>);
|
|
49
|
+
/** @internal for tests only */
|
|
50
|
+
_getPartialConfig(): Partial<MiraAppConfig>;
|
|
51
|
+
/**
|
|
52
|
+
* Set the platform (runtime environment).
|
|
53
|
+
* Required step. The platform provides CryptoService, FileSystem, Path,
|
|
54
|
+
* HttpServerFactory, and AuthService implementations.
|
|
55
|
+
*
|
|
56
|
+
* @param p - A MiraPlatform preset (e.g., NodePlatform)
|
|
57
|
+
* @returns A new builder with "platform" added to the phantom type
|
|
58
|
+
*/
|
|
59
|
+
platform(p: MiraPlatform): MiraBuilder<Has | "platform">;
|
|
60
|
+
/**
|
|
61
|
+
* Set the database backend.
|
|
62
|
+
* Required step. The database provides SqlClient and Dialect implementations.
|
|
63
|
+
*
|
|
64
|
+
* @param d - A MiraDatabase preset (e.g., SqliteDatabase({ filename: "data.db" }))
|
|
65
|
+
* @returns A new builder with "database" added to the phantom type
|
|
66
|
+
*/
|
|
67
|
+
database(d: MiraDatabase): MiraBuilder<Has | "database">;
|
|
68
|
+
/**
|
|
69
|
+
* Set the file storage backend.
|
|
70
|
+
* Required step. Storage provides FileStorage for file upload/download operations.
|
|
71
|
+
*
|
|
72
|
+
* @param s - A MiraStorage preset (e.g., LocalFileStorage({ directory: "./uploads" }))
|
|
73
|
+
* @returns A new builder with "storage" added to the phantom type
|
|
74
|
+
*/
|
|
75
|
+
storage(s: MiraStorage): MiraBuilder<Has | "storage">;
|
|
76
|
+
/**
|
|
77
|
+
* Set the collection definitions.
|
|
78
|
+
* Required step. The collections define the schema, rules, and indexes for all entities.
|
|
79
|
+
*
|
|
80
|
+
* @param c - Array of collection definitions from BaseCollection.define(), AuthCollection.define(),
|
|
81
|
+
* or ViewCollection.define()
|
|
82
|
+
* @returns A new builder with "collections" added to the phantom type
|
|
83
|
+
*/
|
|
84
|
+
collections(c: ReadonlyArray<AnyCollectionDef>): MiraBuilder<Has | "collections">;
|
|
85
|
+
/**
|
|
86
|
+
* Set a custom telemetry layer (optional).
|
|
87
|
+
* Defaults to `ConsoleTelemetryLayer` (prints JSON trace lines to stdout).
|
|
88
|
+
*
|
|
89
|
+
* @param l - A Layer providing telemetry services
|
|
90
|
+
* @returns A new builder with "telemetry" added to the phantom type
|
|
91
|
+
*/
|
|
92
|
+
telemetry(l: Layer.Layer<never, never, never>): MiraBuilder<Has | "telemetry">;
|
|
93
|
+
/**
|
|
94
|
+
* Build the MiraApp from the accumulated configuration.
|
|
95
|
+
* Only compiles when all required steps (platform, database, storage, collections)
|
|
96
|
+
* have been called. If telemetry was not set, defaults to ConsoleTelemetryLayer.
|
|
97
|
+
*
|
|
98
|
+
* @param this - Constrained to MiraBuilder with all four required tags
|
|
99
|
+
* @returns A fully configured MiraApp ready to serve()
|
|
100
|
+
*
|
|
101
|
+
* @throws If build() is called before all required steps are completed
|
|
102
|
+
* (caught at compile time by the phantom type)
|
|
103
|
+
*/
|
|
104
|
+
build(this: MiraBuilder<"platform" | "database" | "storage" | "collections">): MiraApp;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../../src/app/builder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AACnC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACzE,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAElC;;;;;;GAMG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,YAAY,CAAA;IACtB,QAAQ,EAAE,YAAY,CAAA;IACtB,OAAO,EAAE,WAAW,CAAA;IACpB,WAAW,EAAE,aAAa,CAAC,gBAAgB,CAAC,CAAA;IAC5C,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAA;CAC5C;AAWD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,WAAW,CAAC,GAAG,SAAS,MAAM,GAAG,KAAK;;gBAGrC,MAAM,GAAE,OAAO,CAAC,aAAa,CAAM;IAI/C,+BAA+B;IAC/B,iBAAiB,IAAI,OAAO,CAAC,aAAa,CAAC;IAI3C;;;;;;;OAOG;IACH,QAAQ,CAAC,CAAC,EAAE,YAAY,GAAG,WAAW,CAAC,GAAG,GAAG,UAAU,CAAC;IAIxD;;;;;;OAMG;IACH,QAAQ,CAAC,CAAC,EAAE,YAAY,GAAG,WAAW,CAAC,GAAG,GAAG,UAAU,CAAC;IAIxD;;;;;;OAMG;IACH,OAAO,CAAC,CAAC,EAAE,WAAW,GAAG,WAAW,CAAC,GAAG,GAAG,SAAS,CAAC;IAIrD;;;;;;;OAOG;IACH,WAAW,CAAC,CAAC,EAAE,aAAa,CAAC,gBAAgB,CAAC,GAAG,WAAW,CAAC,GAAG,GAAG,aAAa,CAAC;IAIjF;;;;;;OAMG;IACH,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,GAAG,WAAW,CAAC,GAAG,GAAG,WAAW,CAAC;IAI9E;;;;;;;;;;OAUG;IACH,KAAK,CAAC,IAAI,EAAE,WAAW,CAAC,UAAU,GAAG,UAAU,GAAG,SAAS,GAAG,aAAa,CAAC;CAa7E"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { ConsoleTelemetryLayer } from "../telemetry/index.js";
|
|
2
|
+
import { MiraApp } from "./app.js";
|
|
3
|
+
function isMiraAppConfig(config) {
|
|
4
|
+
return (config.platform !== undefined &&
|
|
5
|
+
config.database !== undefined &&
|
|
6
|
+
config.storage !== undefined &&
|
|
7
|
+
config.collections !== undefined);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Phantom-type builder for constructing a `MiraApp`.
|
|
11
|
+
*
|
|
12
|
+
* Uses TypeScript's type system to enforce that all required steps are called
|
|
13
|
+
* before `build()` is allowed. The type parameter `Has` tracks which steps have
|
|
14
|
+
* been completed.
|
|
15
|
+
*
|
|
16
|
+
* Required steps (order does not matter):
|
|
17
|
+
* 1. `.platform(p)` — choose Node, Bun, etc.
|
|
18
|
+
* 2. `.database(d)` — choose SQLite, etc.
|
|
19
|
+
* 3. `.storage(s)` — choose LocalFileStorage, S3, etc.
|
|
20
|
+
* 4. `.collections(c)` — provide collection definitions
|
|
21
|
+
*
|
|
22
|
+
* Optional step: `.telemetry(l)` — custom telemetry layer
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* const app = Mira.builder()
|
|
26
|
+
* .platform(NodePlatform)
|
|
27
|
+
* .database(SqliteDatabase({ filename: "data.db" }))
|
|
28
|
+
* .storage(LocalFileStorage({ directory: "./uploads" }))
|
|
29
|
+
* .collections([Posts, Users])
|
|
30
|
+
* .build()
|
|
31
|
+
* .serve()
|
|
32
|
+
*
|
|
33
|
+
* @see MiraApp — the assembled application
|
|
34
|
+
* @see Mira.builder — entry point
|
|
35
|
+
*/
|
|
36
|
+
export class MiraBuilder {
|
|
37
|
+
#config;
|
|
38
|
+
constructor(config = {}) {
|
|
39
|
+
this.#config = config;
|
|
40
|
+
}
|
|
41
|
+
/** @internal for tests only */
|
|
42
|
+
_getPartialConfig() {
|
|
43
|
+
return this.#config;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Set the platform (runtime environment).
|
|
47
|
+
* Required step. The platform provides CryptoService, FileSystem, Path,
|
|
48
|
+
* HttpServerFactory, and AuthService implementations.
|
|
49
|
+
*
|
|
50
|
+
* @param p - A MiraPlatform preset (e.g., NodePlatform)
|
|
51
|
+
* @returns A new builder with "platform" added to the phantom type
|
|
52
|
+
*/
|
|
53
|
+
platform(p) {
|
|
54
|
+
return new MiraBuilder({ ...this.#config, platform: p });
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Set the database backend.
|
|
58
|
+
* Required step. The database provides SqlClient and Dialect implementations.
|
|
59
|
+
*
|
|
60
|
+
* @param d - A MiraDatabase preset (e.g., SqliteDatabase({ filename: "data.db" }))
|
|
61
|
+
* @returns A new builder with "database" added to the phantom type
|
|
62
|
+
*/
|
|
63
|
+
database(d) {
|
|
64
|
+
return new MiraBuilder({ ...this.#config, database: d });
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Set the file storage backend.
|
|
68
|
+
* Required step. Storage provides FileStorage for file upload/download operations.
|
|
69
|
+
*
|
|
70
|
+
* @param s - A MiraStorage preset (e.g., LocalFileStorage({ directory: "./uploads" }))
|
|
71
|
+
* @returns A new builder with "storage" added to the phantom type
|
|
72
|
+
*/
|
|
73
|
+
storage(s) {
|
|
74
|
+
return new MiraBuilder({ ...this.#config, storage: s });
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Set the collection definitions.
|
|
78
|
+
* Required step. The collections define the schema, rules, and indexes for all entities.
|
|
79
|
+
*
|
|
80
|
+
* @param c - Array of collection definitions from BaseCollection.define(), AuthCollection.define(),
|
|
81
|
+
* or ViewCollection.define()
|
|
82
|
+
* @returns A new builder with "collections" added to the phantom type
|
|
83
|
+
*/
|
|
84
|
+
collections(c) {
|
|
85
|
+
return new MiraBuilder({ ...this.#config, collections: c });
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Set a custom telemetry layer (optional).
|
|
89
|
+
* Defaults to `ConsoleTelemetryLayer` (prints JSON trace lines to stdout).
|
|
90
|
+
*
|
|
91
|
+
* @param l - A Layer providing telemetry services
|
|
92
|
+
* @returns A new builder with "telemetry" added to the phantom type
|
|
93
|
+
*/
|
|
94
|
+
telemetry(l) {
|
|
95
|
+
return new MiraBuilder({ ...this.#config, telemetry: l });
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Build the MiraApp from the accumulated configuration.
|
|
99
|
+
* Only compiles when all required steps (platform, database, storage, collections)
|
|
100
|
+
* have been called. If telemetry was not set, defaults to ConsoleTelemetryLayer.
|
|
101
|
+
*
|
|
102
|
+
* @param this - Constrained to MiraBuilder with all four required tags
|
|
103
|
+
* @returns A fully configured MiraApp ready to serve()
|
|
104
|
+
*
|
|
105
|
+
* @throws If build() is called before all required steps are completed
|
|
106
|
+
* (caught at compile time by the phantom type)
|
|
107
|
+
*/
|
|
108
|
+
build() {
|
|
109
|
+
const config = this._getPartialConfig();
|
|
110
|
+
if (!isMiraAppConfig(config)) {
|
|
111
|
+
throw new Error("build() called on incomplete builder");
|
|
112
|
+
}
|
|
113
|
+
return new MiraApp({
|
|
114
|
+
platform: config.platform,
|
|
115
|
+
database: config.database,
|
|
116
|
+
storage: config.storage,
|
|
117
|
+
collections: config.collections,
|
|
118
|
+
telemetry: config.telemetry ?? ConsoleTelemetryLayer
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.js","sourceRoot":"","sources":["../../../src/app/builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAI5D,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAiBlC,SAAS,eAAe,CAAC,MAA8B;IACrD,OAAO,CACL,MAAM,CAAC,QAAQ,KAAK,SAAS;QAC7B,MAAM,CAAC,QAAQ,KAAK,SAAS;QAC7B,MAAM,CAAC,OAAO,KAAK,SAAS;QAC5B,MAAM,CAAC,WAAW,KAAK,SAAS,CACjC,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,OAAO,WAAW;IACb,OAAO,CAAwB;IAExC,YAAY,SAAiC,EAAE;QAC7C,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;IACvB,CAAC;IAED,+BAA+B;IAC/B,iBAAiB;QACf,OAAO,IAAI,CAAC,OAAO,CAAA;IACrB,CA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