@pattern-stack/codegen 0.2.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/CHANGELOG.md +67 -0
- package/README.md +214 -0
- package/dist/runtime/analytics/index.d.ts +6 -0
- package/dist/runtime/analytics/index.js +49 -0
- package/dist/runtime/analytics/index.js.map +1 -0
- package/dist/runtime/analytics/metrics.d.ts +75 -0
- package/dist/runtime/analytics/metrics.js +1 -0
- package/dist/runtime/analytics/metrics.js.map +1 -0
- package/dist/runtime/analytics/packs/crm-entity-measures.d.ts +21 -0
- package/dist/runtime/analytics/packs/crm-entity-measures.js +1 -0
- package/dist/runtime/analytics/packs/crm-entity-measures.js.map +1 -0
- package/dist/runtime/analytics/packs/index.d.ts +3 -0
- package/dist/runtime/analytics/packs/index.js +1 -0
- package/dist/runtime/analytics/packs/index.js.map +1 -0
- package/dist/runtime/analytics/packs/monetary-measures.d.ts +21 -0
- package/dist/runtime/analytics/packs/monetary-measures.js +1 -0
- package/dist/runtime/analytics/packs/monetary-measures.js.map +1 -0
- package/dist/runtime/analytics/specs.d.ts +49 -0
- package/dist/runtime/analytics/specs.js +1 -0
- package/dist/runtime/analytics/specs.js.map +1 -0
- package/dist/runtime/analytics/types.d.ts +85 -0
- package/dist/runtime/analytics/types.js +49 -0
- package/dist/runtime/analytics/types.js.map +1 -0
- package/dist/runtime/base-classes/activity-entity-repository.d.ts +26 -0
- package/dist/runtime/base-classes/activity-entity-repository.js +195 -0
- package/dist/runtime/base-classes/activity-entity-repository.js.map +1 -0
- package/dist/runtime/base-classes/activity-entity-service.d.ts +39 -0
- package/dist/runtime/base-classes/activity-entity-service.js +214 -0
- package/dist/runtime/base-classes/activity-entity-service.js.map +1 -0
- package/dist/runtime/base-classes/base-read-use-cases.d.ts +68 -0
- package/dist/runtime/base-classes/base-read-use-cases.js +32 -0
- package/dist/runtime/base-classes/base-read-use-cases.js.map +1 -0
- package/dist/runtime/base-classes/base-repository.d.ts +99 -0
- package/dist/runtime/base-classes/base-repository.js +160 -0
- package/dist/runtime/base-classes/base-repository.js.map +1 -0
- package/dist/runtime/base-classes/base-service.d.ts +98 -0
- package/dist/runtime/base-classes/base-service.js +186 -0
- package/dist/runtime/base-classes/base-service.js.map +1 -0
- package/dist/runtime/base-classes/index.d.ts +18 -0
- package/dist/runtime/base-classes/index.js +617 -0
- package/dist/runtime/base-classes/index.js.map +1 -0
- package/dist/runtime/base-classes/knowledge-entity-repository.d.ts +17 -0
- package/dist/runtime/base-classes/knowledge-entity-repository.js +166 -0
- package/dist/runtime/base-classes/knowledge-entity-repository.js.map +1 -0
- package/dist/runtime/base-classes/knowledge-entity-service.d.ts +15 -0
- package/dist/runtime/base-classes/knowledge-entity-service.js +192 -0
- package/dist/runtime/base-classes/knowledge-entity-service.js.map +1 -0
- package/dist/runtime/base-classes/lifecycle-events.d.ts +49 -0
- package/dist/runtime/base-classes/lifecycle-events.js +76 -0
- package/dist/runtime/base-classes/lifecycle-events.js.map +1 -0
- package/dist/runtime/base-classes/metadata-entity-repository.d.ts +27 -0
- package/dist/runtime/base-classes/metadata-entity-repository.js +212 -0
- package/dist/runtime/base-classes/metadata-entity-repository.js.map +1 -0
- package/dist/runtime/base-classes/metadata-entity-service.d.ts +39 -0
- package/dist/runtime/base-classes/metadata-entity-service.js +214 -0
- package/dist/runtime/base-classes/metadata-entity-service.js.map +1 -0
- package/dist/runtime/base-classes/synced-entity-repository.d.ts +32 -0
- package/dist/runtime/base-classes/synced-entity-repository.js +203 -0
- package/dist/runtime/base-classes/synced-entity-repository.js.map +1 -0
- package/dist/runtime/base-classes/synced-entity-service.d.ts +41 -0
- package/dist/runtime/base-classes/synced-entity-service.js +215 -0
- package/dist/runtime/base-classes/synced-entity-service.js.map +1 -0
- package/dist/runtime/base-classes/with-analytics.d.ts +18 -0
- package/dist/runtime/base-classes/with-analytics.js +11 -0
- package/dist/runtime/base-classes/with-analytics.js.map +1 -0
- package/dist/runtime/constants/tokens.d.ts +29 -0
- package/dist/runtime/constants/tokens.js +8 -0
- package/dist/runtime/constants/tokens.js.map +1 -0
- package/dist/runtime/subsystems/analytics/analytics-query.protocol.d.ts +30 -0
- package/dist/runtime/subsystems/analytics/analytics-query.protocol.js +1 -0
- package/dist/runtime/subsystems/analytics/analytics-query.protocol.js.map +1 -0
- package/dist/runtime/subsystems/analytics/analytics.module.d.ts +34 -0
- package/dist/runtime/subsystems/analytics/analytics.module.js +117 -0
- package/dist/runtime/subsystems/analytics/analytics.module.js.map +1 -0
- package/dist/runtime/subsystems/analytics/analytics.tokens.d.ts +24 -0
- package/dist/runtime/subsystems/analytics/analytics.tokens.js +10 -0
- package/dist/runtime/subsystems/analytics/analytics.tokens.js.map +1 -0
- package/dist/runtime/subsystems/analytics/cube-backend.d.ts +28 -0
- package/dist/runtime/subsystems/analytics/cube-backend.js +71 -0
- package/dist/runtime/subsystems/analytics/cube-backend.js.map +1 -0
- package/dist/runtime/subsystems/analytics/index.d.ts +6 -0
- package/dist/runtime/subsystems/analytics/index.js +122 -0
- package/dist/runtime/subsystems/analytics/index.js.map +1 -0
- package/dist/runtime/subsystems/analytics/noop-backend.d.ts +7 -0
- package/dist/runtime/subsystems/analytics/noop-backend.js +25 -0
- package/dist/runtime/subsystems/analytics/noop-backend.js.map +1 -0
- package/dist/runtime/subsystems/cache/cache.drizzle-backend.d.ts +43 -0
- package/dist/runtime/subsystems/cache/cache.drizzle-backend.js +133 -0
- package/dist/runtime/subsystems/cache/cache.drizzle-backend.js.map +1 -0
- package/dist/runtime/subsystems/cache/cache.memory-backend.d.ts +21 -0
- package/dist/runtime/subsystems/cache/cache.memory-backend.js +100 -0
- package/dist/runtime/subsystems/cache/cache.memory-backend.js.map +1 -0
- package/dist/runtime/subsystems/cache/cache.module.d.ts +37 -0
- package/dist/runtime/subsystems/cache/cache.module.js +272 -0
- package/dist/runtime/subsystems/cache/cache.module.js.map +1 -0
- package/dist/runtime/subsystems/cache/cache.protocol.d.ts +42 -0
- package/dist/runtime/subsystems/cache/cache.protocol.js +1 -0
- package/dist/runtime/subsystems/cache/cache.protocol.js.map +1 -0
- package/dist/runtime/subsystems/cache/cache.schema.d.ts +64 -0
- package/dist/runtime/subsystems/cache/cache.schema.js +18 -0
- package/dist/runtime/subsystems/cache/cache.schema.js.map +1 -0
- package/dist/runtime/subsystems/cache/cache.tokens.d.ts +18 -0
- package/dist/runtime/subsystems/cache/cache.tokens.js +8 -0
- package/dist/runtime/subsystems/cache/cache.tokens.js.map +1 -0
- package/dist/runtime/subsystems/cache/index.d.ts +11 -0
- package/dist/runtime/subsystems/cache/index.js +277 -0
- package/dist/runtime/subsystems/cache/index.js.map +1 -0
- package/dist/runtime/subsystems/events/domain-events.schema.d.ts +187 -0
- package/dist/runtime/subsystems/events/domain-events.schema.js +32 -0
- package/dist/runtime/subsystems/events/domain-events.schema.js.map +1 -0
- package/dist/runtime/subsystems/events/event-bus.drizzle-backend.d.ts +38 -0
- package/dist/runtime/subsystems/events/event-bus.drizzle-backend.js +199 -0
- package/dist/runtime/subsystems/events/event-bus.drizzle-backend.js.map +1 -0
- package/dist/runtime/subsystems/events/event-bus.memory-backend.d.ts +18 -0
- package/dist/runtime/subsystems/events/event-bus.memory-backend.js +71 -0
- package/dist/runtime/subsystems/events/event-bus.memory-backend.js.map +1 -0
- package/dist/runtime/subsystems/events/event-bus.protocol.d.ts +52 -0
- package/dist/runtime/subsystems/events/event-bus.protocol.js +1 -0
- package/dist/runtime/subsystems/events/event-bus.protocol.js.map +1 -0
- package/dist/runtime/subsystems/events/event-bus.redis-backend.d.ts +95 -0
- package/dist/runtime/subsystems/events/event-bus.redis-backend.js +229 -0
- package/dist/runtime/subsystems/events/event-bus.redis-backend.js.map +1 -0
- package/dist/runtime/subsystems/events/events.module.d.ts +46 -0
- package/dist/runtime/subsystems/events/events.module.js +531 -0
- package/dist/runtime/subsystems/events/events.module.js.map +1 -0
- package/dist/runtime/subsystems/events/events.tokens.d.ts +19 -0
- package/dist/runtime/subsystems/events/events.tokens.js +8 -0
- package/dist/runtime/subsystems/events/events.tokens.js.map +1 -0
- package/dist/runtime/subsystems/events/index.d.ts +12 -0
- package/dist/runtime/subsystems/events/index.js +536 -0
- package/dist/runtime/subsystems/events/index.js.map +1 -0
- package/dist/runtime/subsystems/index.d.ts +24 -0
- package/dist/runtime/subsystems/index.js +1643 -0
- package/dist/runtime/subsystems/index.js.map +1 -0
- package/dist/runtime/subsystems/jobs/index.d.ts +14 -0
- package/dist/runtime/subsystems/jobs/index.js +680 -0
- package/dist/runtime/subsystems/jobs/index.js.map +1 -0
- package/dist/runtime/subsystems/jobs/job-queue.bullmq-backend.d.ts +54 -0
- package/dist/runtime/subsystems/jobs/job-queue.bullmq-backend.js +186 -0
- package/dist/runtime/subsystems/jobs/job-queue.bullmq-backend.js.map +1 -0
- package/dist/runtime/subsystems/jobs/job-queue.drizzle-backend.d.ts +38 -0
- package/dist/runtime/subsystems/jobs/job-queue.drizzle-backend.js +228 -0
- package/dist/runtime/subsystems/jobs/job-queue.drizzle-backend.js.map +1 -0
- package/dist/runtime/subsystems/jobs/job-queue.memory-backend.d.ts +12 -0
- package/dist/runtime/subsystems/jobs/job-queue.memory-backend.js +44 -0
- package/dist/runtime/subsystems/jobs/job-queue.memory-backend.js.map +1 -0
- package/dist/runtime/subsystems/jobs/job-queue.protocol.d.ts +48 -0
- package/dist/runtime/subsystems/jobs/job-queue.protocol.js +1 -0
- package/dist/runtime/subsystems/jobs/job-queue.protocol.js.map +1 -0
- package/dist/runtime/subsystems/jobs/job-queue.redis-backend.d.ts +46 -0
- package/dist/runtime/subsystems/jobs/job-queue.redis-backend.js +187 -0
- package/dist/runtime/subsystems/jobs/job-queue.redis-backend.js.map +1 -0
- package/dist/runtime/subsystems/jobs/job-queue.schema.d.ts +237 -0
- package/dist/runtime/subsystems/jobs/job-queue.schema.js +44 -0
- package/dist/runtime/subsystems/jobs/job-queue.schema.js.map +1 -0
- package/dist/runtime/subsystems/jobs/jobs.module.d.ts +18 -0
- package/dist/runtime/subsystems/jobs/jobs.module.js +676 -0
- package/dist/runtime/subsystems/jobs/jobs.module.js.map +1 -0
- package/dist/runtime/subsystems/jobs/jobs.tokens.d.ts +13 -0
- package/dist/runtime/subsystems/jobs/jobs.tokens.js +8 -0
- package/dist/runtime/subsystems/jobs/jobs.tokens.js.map +1 -0
- package/dist/runtime/subsystems/storage/index.d.ts +6 -0
- package/dist/runtime/subsystems/storage/index.js +204 -0
- package/dist/runtime/subsystems/storage/index.js.map +1 -0
- package/dist/runtime/subsystems/storage/storage.local-backend.d.ts +18 -0
- package/dist/runtime/subsystems/storage/storage.local-backend.js +108 -0
- package/dist/runtime/subsystems/storage/storage.local-backend.js.map +1 -0
- package/dist/runtime/subsystems/storage/storage.memory-backend.d.ts +28 -0
- package/dist/runtime/subsystems/storage/storage.memory-backend.js +72 -0
- package/dist/runtime/subsystems/storage/storage.memory-backend.js.map +1 -0
- package/dist/runtime/subsystems/storage/storage.module.d.ts +40 -0
- package/dist/runtime/subsystems/storage/storage.module.js +201 -0
- package/dist/runtime/subsystems/storage/storage.module.js.map +1 -0
- package/dist/runtime/subsystems/storage/storage.protocol.d.ts +69 -0
- package/dist/runtime/subsystems/storage/storage.protocol.js +1 -0
- package/dist/runtime/subsystems/storage/storage.protocol.js.map +1 -0
- package/dist/runtime/subsystems/storage/storage.tokens.d.ts +11 -0
- package/dist/runtime/subsystems/storage/storage.tokens.js +6 -0
- package/dist/runtime/subsystems/storage/storage.tokens.js.map +1 -0
- package/dist/runtime/subsystems/storage/storage.utils.d.ts +9 -0
- package/dist/runtime/subsystems/storage/storage.utils.js +18 -0
- package/dist/runtime/subsystems/storage/storage.utils.js.map +1 -0
- package/dist/runtime/types/drizzle.d.ts +17 -0
- package/dist/runtime/types/drizzle.js +1 -0
- package/dist/runtime/types/drizzle.js.map +1 -0
- package/dist/src/cli/index.d.ts +1 -0
- package/dist/src/cli/index.js +7365 -0
- package/dist/src/cli/index.js.map +1 -0
- package/dist/src/index.d.ts +2384 -0
- package/dist/src/index.js +2198 -0
- package/dist/src/index.js.map +1 -0
- package/package.json +114 -0
- package/templates/broadcast/new/backend-interface.ejs.t +47 -0
- package/templates/broadcast/new/bridge-listener.ejs.t +67 -0
- package/templates/broadcast/new/channel.ejs.t +77 -0
- package/templates/broadcast/new/index.ejs.t +21 -0
- package/templates/broadcast/new/memory-backend.ejs.t +87 -0
- package/templates/broadcast/new/module.ejs.t +57 -0
- package/templates/broadcast/new/prompt.js +268 -0
- package/templates/broadcast/new/websocket-backend.ejs.t +259 -0
- package/templates/entity/new/backend/application/commands/create.ejs.t +55 -0
- package/templates/entity/new/backend/application/commands/delete.ejs.t +45 -0
- package/templates/entity/new/backend/application/commands/grouped-index.ejs.t +149 -0
- package/templates/entity/new/backend/application/commands/index.ejs.t +15 -0
- package/templates/entity/new/backend/application/commands/update.ejs.t +58 -0
- package/templates/entity/new/backend/application/queries/declarative-queries.ejs.t +36 -0
- package/templates/entity/new/backend/application/queries/get-by-id.ejs.t +42 -0
- package/templates/entity/new/backend/application/queries/grouped-index.ejs.t +81 -0
- package/templates/entity/new/backend/application/queries/index.ejs.t +14 -0
- package/templates/entity/new/backend/application/queries/list.ejs.t +36 -0
- package/templates/entity/new/backend/application/schemas/_inject-index.ejs.t +7 -0
- package/templates/entity/new/backend/application/schemas/dto.ejs.t +45 -0
- package/templates/entity/new/backend/database/_inject-index.ejs.t +7 -0
- package/templates/entity/new/backend/database/electric-migration.ejs.t +21 -0
- package/templates/entity/new/backend/database/repository.ejs.t +450 -0
- package/templates/entity/new/backend/database/schema.ejs.t +248 -0
- package/templates/entity/new/backend/domain/_inject-index.ejs.t +12 -0
- package/templates/entity/new/backend/domain/entity.ejs.t +108 -0
- package/templates/entity/new/backend/domain/grouped-index.ejs.t +163 -0
- package/templates/entity/new/backend/domain/index.ejs.t +15 -0
- package/templates/entity/new/backend/domain/repository-interface.ejs.t +71 -0
- package/templates/entity/new/backend/modules/core/_ensure-anchor-tokens.ejs.t +10 -0
- package/templates/entity/new/backend/modules/core/_inject-token.ejs.t +7 -0
- package/templates/entity/new/backend/modules/core/module.ejs.t +67 -0
- package/templates/entity/new/backend/modules/trpc/module.ejs.t +67 -0
- package/templates/entity/new/backend/presentation/controller.ejs.t +201 -0
- package/templates/entity/new/clean-lite-ps/controller.ejs.t +37 -0
- package/templates/entity/new/clean-lite-ps/dto/create.ejs.t +17 -0
- package/templates/entity/new/clean-lite-ps/dto/output.ejs.t +25 -0
- package/templates/entity/new/clean-lite-ps/dto/update.ejs.t +11 -0
- package/templates/entity/new/clean-lite-ps/entity.ejs.t +52 -0
- package/templates/entity/new/clean-lite-ps/index.ejs.t +20 -0
- package/templates/entity/new/clean-lite-ps/module.ejs.t +43 -0
- package/templates/entity/new/clean-lite-ps/prompt-extension.js +617 -0
- package/templates/entity/new/clean-lite-ps/repository.ejs.t +62 -0
- package/templates/entity/new/clean-lite-ps/service.ejs.t +34 -0
- package/templates/entity/new/clean-lite-ps/use-cases/declarative-queries.ejs.t +34 -0
- package/templates/entity/new/clean-lite-ps/use-cases/find-by-id.ejs.t +16 -0
- package/templates/entity/new/clean-lite-ps/use-cases/list.ejs.t +16 -0
- package/templates/entity/new/frontend/_inject-entities-entry.ejs.t +7 -0
- package/templates/entity/new/frontend/_inject-entities-import.ejs.t +7 -0
- package/templates/entity/new/frontend/collections/_ensure-anchor-collections.ejs.t +10 -0
- package/templates/entity/new/frontend/collections/_inject-index.ejs.t +9 -0
- package/templates/entity/new/frontend/collections/_inject-schema-import.ejs.t +9 -0
- package/templates/entity/new/frontend/collections/collection.ejs.t +61 -0
- package/templates/entity/new/frontend/collections/collections-base.ejs.t +24 -0
- package/templates/entity/new/frontend/entity/collection.ejs.t +172 -0
- package/templates/entity/new/frontend/entity/combined.ejs.t +474 -0
- package/templates/entity/new/frontend/entity/fields.ejs.t +104 -0
- package/templates/entity/new/frontend/entity/hooks.ejs.t +73 -0
- package/templates/entity/new/frontend/entity/index.ejs.t +21 -0
- package/templates/entity/new/frontend/entity/mutation-hooks.ejs.t +84 -0
- package/templates/entity/new/frontend/entity/mutations.ejs.t +38 -0
- package/templates/entity/new/frontend/entity/types.ejs.t +59 -0
- package/templates/entity/new/frontend/generated/_inject-index-export.ejs.t +7 -0
- package/templates/entity/new/frontend/generated/_inject-index-import.ejs.t +7 -0
- package/templates/entity/new/frontend/generated/_inject-index-registry.ejs.t +7 -0
- package/templates/entity/new/frontend/store/_inject-collection-import.ejs.t +9 -0
- package/templates/entity/new/frontend/store/_inject-collections.ejs.t +9 -0
- package/templates/entity/new/frontend/store/_inject-entity.ejs.t +9 -0
- package/templates/entity/new/frontend/store/_inject-import.ejs.t +9 -0
- package/templates/entity/new/frontend/store/_inject-lookups.ejs.t +9 -0
- package/templates/entity/new/frontend/store/_inject-resolve.ejs.t +10 -0
- package/templates/entity/new/frontend/store/hooks.ejs.t +72 -0
- package/templates/entity/new/frontend/unified-entity.ejs.t +28 -0
- package/templates/entity/new/prompt.js +1421 -0
- package/templates/relationship/new/controller.ejs.t +36 -0
- package/templates/relationship/new/dto/create.ejs.t +41 -0
- package/templates/relationship/new/dto/output.ejs.t +44 -0
- package/templates/relationship/new/dto/update.ejs.t +10 -0
- package/templates/relationship/new/entity.ejs.t +98 -0
- package/templates/relationship/new/index.ejs.t +19 -0
- package/templates/relationship/new/module.ejs.t +35 -0
- package/templates/relationship/new/prompt.js +682 -0
- package/templates/relationship/new/repository.ejs.t +54 -0
- package/templates/relationship/new/service.ejs.t +31 -0
- package/templates/relationship/new/use-cases/declarative-queries.ejs.t +34 -0
- package/templates/relationship/new/use-cases/find-by-id.ejs.t +16 -0
- package/templates/relationship/new/use-cases/list.ejs.t +16 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Storage subsystem — NestJS module factory
|
|
5
|
+
*
|
|
6
|
+
* Register once in AppModule (global: true means all other modules can inject
|
|
7
|
+
* STORAGE without importing StorageModule themselves):
|
|
8
|
+
*
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // app.module.ts
|
|
11
|
+
* @Module({
|
|
12
|
+
* imports: [
|
|
13
|
+
* StorageModule.forRoot({ backend: 'local', basePath: './uploads' }),
|
|
14
|
+
* ],
|
|
15
|
+
* })
|
|
16
|
+
* export class AppModule {}
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* Swap to memory backend in tests:
|
|
20
|
+
* ```typescript
|
|
21
|
+
* Test.createTestingModule({
|
|
22
|
+
* imports: [StorageModule.forRoot({ backend: 'memory' })],
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
interface StorageModuleOptions {
|
|
28
|
+
/** Which backend to activate. */
|
|
29
|
+
backend: 'local' | 'memory';
|
|
30
|
+
/**
|
|
31
|
+
* Base path for the local backend (resolved to an absolute path).
|
|
32
|
+
* Ignored when backend is 'memory'. Defaults to `./storage`.
|
|
33
|
+
*/
|
|
34
|
+
basePath?: string;
|
|
35
|
+
}
|
|
36
|
+
declare class StorageModule {
|
|
37
|
+
static forRoot(options?: StorageModuleOptions): DynamicModule;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { StorageModule, type StorageModuleOptions };
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result) __defProp(target, key, result);
|
|
9
|
+
return result;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// runtime/subsystems/storage/storage.module.ts
|
|
13
|
+
import { Module } from "@nestjs/common";
|
|
14
|
+
|
|
15
|
+
// runtime/subsystems/storage/storage.local-backend.ts
|
|
16
|
+
import {
|
|
17
|
+
createReadStream,
|
|
18
|
+
existsSync,
|
|
19
|
+
mkdirSync,
|
|
20
|
+
readdirSync,
|
|
21
|
+
readFileSync,
|
|
22
|
+
unlinkSync,
|
|
23
|
+
writeFileSync
|
|
24
|
+
} from "fs";
|
|
25
|
+
import { dirname, join, relative, resolve, sep } from "path";
|
|
26
|
+
import { Readable } from "stream";
|
|
27
|
+
|
|
28
|
+
// runtime/subsystems/storage/storage.utils.ts
|
|
29
|
+
async function toBuffer(data) {
|
|
30
|
+
if (Buffer.isBuffer(data)) {
|
|
31
|
+
return data;
|
|
32
|
+
}
|
|
33
|
+
const reader = data.getReader();
|
|
34
|
+
const chunks = [];
|
|
35
|
+
while (true) {
|
|
36
|
+
const { done, value } = await reader.read();
|
|
37
|
+
if (done) break;
|
|
38
|
+
if (value) chunks.push(value);
|
|
39
|
+
}
|
|
40
|
+
return Buffer.concat(chunks);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// runtime/subsystems/storage/storage.local-backend.ts
|
|
44
|
+
var LocalStorageBackend = class {
|
|
45
|
+
basePath;
|
|
46
|
+
constructor(basePath = "./storage") {
|
|
47
|
+
this.basePath = resolve(basePath);
|
|
48
|
+
}
|
|
49
|
+
async upload(key, data, contentType) {
|
|
50
|
+
const filePath = this.resolvePath(key);
|
|
51
|
+
mkdirSync(dirname(filePath), { recursive: true });
|
|
52
|
+
const buffer = await toBuffer(data);
|
|
53
|
+
writeFileSync(filePath, buffer);
|
|
54
|
+
return key;
|
|
55
|
+
}
|
|
56
|
+
async download(key) {
|
|
57
|
+
const filePath = this.resolvePath(key);
|
|
58
|
+
if (!existsSync(filePath)) {
|
|
59
|
+
throw new Error(`Storage: file not found: ${key}`);
|
|
60
|
+
}
|
|
61
|
+
return readFileSync(filePath);
|
|
62
|
+
}
|
|
63
|
+
async delete(key) {
|
|
64
|
+
const filePath = this.resolvePath(key);
|
|
65
|
+
if (!existsSync(filePath)) {
|
|
66
|
+
throw new Error(`Storage: file not found: ${key}`);
|
|
67
|
+
}
|
|
68
|
+
unlinkSync(filePath);
|
|
69
|
+
}
|
|
70
|
+
async getUrl(key, _expiresInSeconds) {
|
|
71
|
+
const filePath = this.resolvePath(key);
|
|
72
|
+
if (!existsSync(filePath)) {
|
|
73
|
+
throw new Error(`Storage: file not found: ${key}`);
|
|
74
|
+
}
|
|
75
|
+
return `file://${filePath}`;
|
|
76
|
+
}
|
|
77
|
+
async exists(key) {
|
|
78
|
+
try {
|
|
79
|
+
return existsSync(this.resolvePath(key));
|
|
80
|
+
} catch {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async list(prefix) {
|
|
85
|
+
const keys = this.listRecursive(this.basePath);
|
|
86
|
+
if (prefix === void 0) return keys;
|
|
87
|
+
return keys.filter((k) => k.startsWith(prefix));
|
|
88
|
+
}
|
|
89
|
+
async downloadStream(key) {
|
|
90
|
+
const filePath = this.resolvePath(key);
|
|
91
|
+
if (!existsSync(filePath)) {
|
|
92
|
+
throw new Error(`Storage: file not found: ${key}`);
|
|
93
|
+
}
|
|
94
|
+
const nodeStream = createReadStream(filePath);
|
|
95
|
+
return Readable.toWeb(nodeStream);
|
|
96
|
+
}
|
|
97
|
+
resolvePath(key) {
|
|
98
|
+
const resolved = resolve(this.basePath, key);
|
|
99
|
+
if (!resolved.startsWith(this.basePath + sep)) {
|
|
100
|
+
throw new Error(`Invalid storage key (path traversal attempt): ${key}`);
|
|
101
|
+
}
|
|
102
|
+
return resolved;
|
|
103
|
+
}
|
|
104
|
+
/** Recursively list all files under dir, returning keys relative to basePath. */
|
|
105
|
+
listRecursive(dir) {
|
|
106
|
+
if (!existsSync(dir)) return [];
|
|
107
|
+
const keys = [];
|
|
108
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
109
|
+
const full = join(dir, entry.name);
|
|
110
|
+
if (entry.isDirectory()) {
|
|
111
|
+
keys.push(...this.listRecursive(full));
|
|
112
|
+
} else {
|
|
113
|
+
keys.push(relative(this.basePath, full));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return keys;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// runtime/subsystems/storage/storage.memory-backend.ts
|
|
121
|
+
var MemoryStorageBackend = class {
|
|
122
|
+
store = /* @__PURE__ */ new Map();
|
|
123
|
+
async upload(key, data, contentType) {
|
|
124
|
+
const buffer = await toBuffer(data);
|
|
125
|
+
this.store.set(key, { data: buffer, contentType });
|
|
126
|
+
return key;
|
|
127
|
+
}
|
|
128
|
+
async download(key) {
|
|
129
|
+
const entry = this.store.get(key);
|
|
130
|
+
if (!entry) {
|
|
131
|
+
throw new Error(`Storage: file not found: ${key}`);
|
|
132
|
+
}
|
|
133
|
+
return entry.data;
|
|
134
|
+
}
|
|
135
|
+
async delete(key) {
|
|
136
|
+
if (!this.store.has(key)) {
|
|
137
|
+
throw new Error(`Storage: file not found: ${key}`);
|
|
138
|
+
}
|
|
139
|
+
this.store.delete(key);
|
|
140
|
+
}
|
|
141
|
+
async getUrl(key, _expiresInSeconds) {
|
|
142
|
+
if (!this.store.has(key)) {
|
|
143
|
+
throw new Error(`Storage: file not found: ${key}`);
|
|
144
|
+
}
|
|
145
|
+
return `memory://${key}`;
|
|
146
|
+
}
|
|
147
|
+
async exists(key) {
|
|
148
|
+
return this.store.has(key);
|
|
149
|
+
}
|
|
150
|
+
async list(prefix) {
|
|
151
|
+
const keys = Array.from(this.store.keys());
|
|
152
|
+
if (prefix === void 0) return keys;
|
|
153
|
+
return keys.filter((k) => k.startsWith(prefix));
|
|
154
|
+
}
|
|
155
|
+
async downloadStream(key) {
|
|
156
|
+
const buffer = await this.download(key);
|
|
157
|
+
return new ReadableStream({
|
|
158
|
+
start(controller) {
|
|
159
|
+
controller.enqueue(new Uint8Array(buffer));
|
|
160
|
+
controller.close();
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
/** Clear all stored files. Useful for test teardown. */
|
|
165
|
+
clear() {
|
|
166
|
+
this.store.clear();
|
|
167
|
+
}
|
|
168
|
+
/** Return number of stored files. Useful for test assertions. */
|
|
169
|
+
size() {
|
|
170
|
+
return this.store.size;
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// runtime/subsystems/storage/storage.tokens.ts
|
|
175
|
+
var STORAGE = /* @__PURE__ */ Symbol("STORAGE");
|
|
176
|
+
|
|
177
|
+
// runtime/subsystems/storage/storage.module.ts
|
|
178
|
+
var StorageModule = class {
|
|
179
|
+
static forRoot(options = { backend: "local" }) {
|
|
180
|
+
const provider = options.backend === "local" ? {
|
|
181
|
+
provide: STORAGE,
|
|
182
|
+
useFactory: () => new LocalStorageBackend(options.basePath ?? "./storage")
|
|
183
|
+
} : {
|
|
184
|
+
provide: STORAGE,
|
|
185
|
+
useClass: MemoryStorageBackend
|
|
186
|
+
};
|
|
187
|
+
return {
|
|
188
|
+
module: StorageModule,
|
|
189
|
+
global: true,
|
|
190
|
+
providers: [provider],
|
|
191
|
+
exports: [STORAGE]
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
StorageModule = __decorateClass([
|
|
196
|
+
Module({})
|
|
197
|
+
], StorageModule);
|
|
198
|
+
export {
|
|
199
|
+
StorageModule
|
|
200
|
+
};
|
|
201
|
+
//# sourceMappingURL=storage.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../runtime/subsystems/storage/storage.module.ts","../../../../runtime/subsystems/storage/storage.local-backend.ts","../../../../runtime/subsystems/storage/storage.utils.ts","../../../../runtime/subsystems/storage/storage.memory-backend.ts","../../../../runtime/subsystems/storage/storage.tokens.ts"],"sourcesContent":["/**\n * Storage subsystem — NestJS module factory\n *\n * Register once in AppModule (global: true means all other modules can inject\n * STORAGE without importing StorageModule themselves):\n *\n * ```typescript\n * // app.module.ts\n * @Module({\n * imports: [\n * StorageModule.forRoot({ backend: 'local', basePath: './uploads' }),\n * ],\n * })\n * export class AppModule {}\n * ```\n *\n * Swap to memory backend in tests:\n * ```typescript\n * Test.createTestingModule({\n * imports: [StorageModule.forRoot({ backend: 'memory' })],\n * });\n * ```\n */\nimport { type DynamicModule, Module } from '@nestjs/common';\nimport { LocalStorageBackend } from './storage.local-backend';\nimport { MemoryStorageBackend } from './storage.memory-backend';\nimport { STORAGE } from './storage.tokens';\n\nexport interface StorageModuleOptions {\n /** Which backend to activate. */\n backend: 'local' | 'memory';\n /**\n * Base path for the local backend (resolved to an absolute path).\n * Ignored when backend is 'memory'. Defaults to `./storage`.\n */\n basePath?: string;\n}\n\n@Module({})\nexport class StorageModule {\n static forRoot(options: StorageModuleOptions = { backend: 'local' }): DynamicModule {\n const provider =\n options.backend === 'local'\n ? {\n provide: STORAGE,\n useFactory: () => new LocalStorageBackend(options.basePath ?? './storage'),\n }\n : {\n provide: STORAGE,\n useClass: MemoryStorageBackend,\n };\n\n return {\n module: StorageModule,\n global: true,\n providers: [provider],\n exports: [STORAGE],\n };\n }\n}\n","/**\n * Storage subsystem — local filesystem backend\n *\n * Writes files to `{basePath}/{key}` on the local filesystem.\n * Suitable for development only — use an S3/GCS backend in production.\n *\n * - Creates intermediate directories automatically (mkdirSync recursive)\n * - getUrl returns a `file://` URI pointing to the absolute path\n * - All methods throw on failure\n * - resolvePath validates against path traversal attacks\n */\nimport {\n createReadStream,\n existsSync,\n mkdirSync,\n readdirSync,\n readFileSync,\n statSync,\n unlinkSync,\n writeFileSync,\n} from 'fs';\nimport { dirname, join, relative, resolve, sep } from 'path';\nimport { Readable } from 'stream';\nimport type { IStorageService } from './storage.protocol';\nimport { toBuffer } from './storage.utils';\n\nexport class LocalStorageBackend implements IStorageService {\n private readonly basePath: string;\n\n constructor(basePath: string = './storage') {\n this.basePath = resolve(basePath);\n }\n\n async upload(key: string, data: Buffer | ReadableStream, contentType?: string): Promise<string> {\n const filePath = this.resolvePath(key);\n mkdirSync(dirname(filePath), { recursive: true });\n\n const buffer = await toBuffer(data);\n writeFileSync(filePath, buffer);\n return key;\n }\n\n async download(key: string): Promise<Buffer> {\n const filePath = this.resolvePath(key);\n if (!existsSync(filePath)) {\n throw new Error(`Storage: file not found: ${key}`);\n }\n return readFileSync(filePath);\n }\n\n async delete(key: string): Promise<void> {\n const filePath = this.resolvePath(key);\n if (!existsSync(filePath)) {\n throw new Error(`Storage: file not found: ${key}`);\n }\n unlinkSync(filePath);\n }\n\n async getUrl(key: string, _expiresInSeconds?: number): Promise<string> {\n const filePath = this.resolvePath(key);\n if (!existsSync(filePath)) {\n throw new Error(`Storage: file not found: ${key}`);\n }\n return `file://${filePath}`;\n }\n\n async exists(key: string): Promise<boolean> {\n try {\n return existsSync(this.resolvePath(key));\n } catch {\n // resolvePath throws on traversal attempt — treat as non-existent\n return false;\n }\n }\n\n async list(prefix?: string): Promise<string[]> {\n const keys = this.listRecursive(this.basePath);\n if (prefix === undefined) return keys;\n return keys.filter((k) => k.startsWith(prefix));\n }\n\n async downloadStream(key: string): Promise<ReadableStream> {\n const filePath = this.resolvePath(key);\n if (!existsSync(filePath)) {\n throw new Error(`Storage: file not found: ${key}`);\n }\n const nodeStream = createReadStream(filePath);\n return Readable.toWeb(nodeStream) as ReadableStream;\n }\n\n private resolvePath(key: string): string {\n const resolved = resolve(this.basePath, key);\n if (!resolved.startsWith(this.basePath + sep)) {\n throw new Error(`Invalid storage key (path traversal attempt): ${key}`);\n }\n return resolved;\n }\n\n /** Recursively list all files under dir, returning keys relative to basePath. */\n private listRecursive(dir: string): string[] {\n if (!existsSync(dir)) return [];\n const keys: string[] = [];\n for (const entry of readdirSync(dir, { withFileTypes: true })) {\n const full = join(dir, entry.name);\n if (entry.isDirectory()) {\n keys.push(...this.listRecursive(full));\n } else {\n keys.push(relative(this.basePath, full));\n }\n }\n return keys;\n }\n}\n","/**\n * Storage subsystem — shared utilities\n */\n\n/**\n * Convert a Buffer or Web ReadableStream to a Node.js Buffer.\n */\nexport async function toBuffer(data: Buffer | ReadableStream): Promise<Buffer> {\n if (Buffer.isBuffer(data)) {\n return data;\n }\n const reader = (data as ReadableStream<Uint8Array>).getReader();\n const chunks: Uint8Array[] = [];\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n if (value) chunks.push(value);\n }\n return Buffer.concat(chunks);\n}\n","/**\n * Storage subsystem — in-memory backend\n *\n * Stores files as Buffers in a Map. Intended for unit tests only.\n * All state is lost when the process exits.\n *\n * - getUrl returns `memory://{key}` (not a real URL, useful for assertions)\n * - All methods throw on failure (missing keys, etc.)\n */\nimport type { IStorageService } from './storage.protocol';\nimport { toBuffer } from './storage.utils';\n\ninterface MemoryEntry {\n data: Buffer;\n contentType?: string;\n}\n\nexport class MemoryStorageBackend implements IStorageService {\n private readonly store = new Map<string, MemoryEntry>();\n\n async upload(key: string, data: Buffer | ReadableStream, contentType?: string): Promise<string> {\n const buffer = await toBuffer(data);\n this.store.set(key, { data: buffer, contentType });\n return key;\n }\n\n async download(key: string): Promise<Buffer> {\n const entry = this.store.get(key);\n if (!entry) {\n throw new Error(`Storage: file not found: ${key}`);\n }\n return entry.data;\n }\n\n async delete(key: string): Promise<void> {\n if (!this.store.has(key)) {\n throw new Error(`Storage: file not found: ${key}`);\n }\n this.store.delete(key);\n }\n\n async getUrl(key: string, _expiresInSeconds?: number): Promise<string> {\n if (!this.store.has(key)) {\n throw new Error(`Storage: file not found: ${key}`);\n }\n return `memory://${key}`;\n }\n\n async exists(key: string): Promise<boolean> {\n return this.store.has(key);\n }\n\n async list(prefix?: string): Promise<string[]> {\n const keys = Array.from(this.store.keys());\n if (prefix === undefined) return keys;\n return keys.filter((k) => k.startsWith(prefix));\n }\n\n async downloadStream(key: string): Promise<ReadableStream> {\n const buffer = await this.download(key);\n return new ReadableStream<Uint8Array>({\n start(controller) {\n controller.enqueue(new Uint8Array(buffer));\n controller.close();\n },\n });\n }\n\n /** Clear all stored files. Useful for test teardown. */\n clear(): void {\n this.store.clear();\n }\n\n /** Return number of stored files. Useful for test assertions. */\n size(): number {\n return this.store.size;\n }\n}\n","/**\n * Injection token for the storage service.\n *\n * Usage in use cases:\n * ```typescript\n * constructor(@Inject(STORAGE) private readonly storage: IStorageService) {}\n * ```\n */\nexport const STORAGE = Symbol('STORAGE');\n"],"mappings":";;;;;;;;;;;;AAuBA,SAA6B,cAAc;;;ACZ3C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,OACK;AACP,SAAS,SAAS,MAAM,UAAU,SAAS,WAAW;AACtD,SAAS,gBAAgB;;;ACfzB,eAAsB,SAAS,MAAgD;AAC7E,MAAI,OAAO,SAAS,IAAI,GAAG;AACzB,WAAO;AAAA,EACT;AACA,QAAM,SAAU,KAAoC,UAAU;AAC9D,QAAM,SAAuB,CAAC;AAC9B,SAAO,MAAM;AACX,UAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,QAAI,KAAM;AACV,QAAI,MAAO,QAAO,KAAK,KAAK;AAAA,EAC9B;AACA,SAAO,OAAO,OAAO,MAAM;AAC7B;;;ADOO,IAAM,sBAAN,MAAqD;AAAA,EACzC;AAAA,EAEjB,YAAY,WAAmB,aAAa;AAC1C,SAAK,WAAW,QAAQ,QAAQ;AAAA,EAClC;AAAA,EAEA,MAAM,OAAO,KAAa,MAA+B,aAAuC;AAC9F,UAAM,WAAW,KAAK,YAAY,GAAG;AACrC,cAAU,QAAQ,QAAQ,GAAG,EAAE,WAAW,KAAK,CAAC;AAEhD,UAAM,SAAS,MAAM,SAAS,IAAI;AAClC,kBAAc,UAAU,MAAM;AAC9B,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,SAAS,KAA8B;AAC3C,UAAM,WAAW,KAAK,YAAY,GAAG;AACrC,QAAI,CAAC,WAAW,QAAQ,GAAG;AACzB,YAAM,IAAI,MAAM,4BAA4B,GAAG,EAAE;AAAA,IACnD;AACA,WAAO,aAAa,QAAQ;AAAA,EAC9B;AAAA,EAEA,MAAM,OAAO,KAA4B;AACvC,UAAM,WAAW,KAAK,YAAY,GAAG;AACrC,QAAI,CAAC,WAAW,QAAQ,GAAG;AACzB,YAAM,IAAI,MAAM,4BAA4B,GAAG,EAAE;AAAA,IACnD;AACA,eAAW,QAAQ;AAAA,EACrB;AAAA,EAEA,MAAM,OAAO,KAAa,mBAA6C;AACrE,UAAM,WAAW,KAAK,YAAY,GAAG;AACrC,QAAI,CAAC,WAAW,QAAQ,GAAG;AACzB,YAAM,IAAI,MAAM,4BAA4B,GAAG,EAAE;AAAA,IACnD;AACA,WAAO,UAAU,QAAQ;AAAA,EAC3B;AAAA,EAEA,MAAM,OAAO,KAA+B;AAC1C,QAAI;AACF,aAAO,WAAW,KAAK,YAAY,GAAG,CAAC;AAAA,IACzC,QAAQ;AAEN,aAAO;AAAA,IACT;AAAA,EACF;AAAA,EAEA,MAAM,KAAK,QAAoC;AAC7C,UAAM,OAAO,KAAK,cAAc,KAAK,QAAQ;AAC7C,QAAI,WAAW,OAAW,QAAO;AACjC,WAAO,KAAK,OAAO,CAAC,MAAM,EAAE,WAAW,MAAM,CAAC;AAAA,EAChD;AAAA,EAEA,MAAM,eAAe,KAAsC;AACzD,UAAM,WAAW,KAAK,YAAY,GAAG;AACrC,QAAI,CAAC,WAAW,QAAQ,GAAG;AACzB,YAAM,IAAI,MAAM,4BAA4B,GAAG,EAAE;AAAA,IACnD;AACA,UAAM,aAAa,iBAAiB,QAAQ;AAC5C,WAAO,SAAS,MAAM,UAAU;AAAA,EAClC;AAAA,EAEQ,YAAY,KAAqB;AACvC,UAAM,WAAW,QAAQ,KAAK,UAAU,GAAG;AAC3C,QAAI,CAAC,SAAS,WAAW,KAAK,WAAW,GAAG,GAAG;AAC7C,YAAM,IAAI,MAAM,iDAAiD,GAAG,EAAE;AAAA,IACxE;AACA,WAAO;AAAA,EACT;AAAA;AAAA,EAGQ,cAAc,KAAuB;AAC3C,QAAI,CAAC,WAAW,GAAG,EAAG,QAAO,CAAC;AAC9B,UAAM,OAAiB,CAAC;AACxB,eAAW,SAAS,YAAY,KAAK,EAAE,eAAe,KAAK,CAAC,GAAG;AAC7D,YAAM,OAAO,KAAK,KAAK,MAAM,IAAI;AACjC,UAAI,MAAM,YAAY,GAAG;AACvB,aAAK,KAAK,GAAG,KAAK,cAAc,IAAI,CAAC;AAAA,MACvC,OAAO;AACL,aAAK,KAAK,SAAS,KAAK,UAAU,IAAI,CAAC;AAAA,MACzC;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;;;AE/FO,IAAM,uBAAN,MAAsD;AAAA,EAC1C,QAAQ,oBAAI,IAAyB;AAAA,EAEtD,MAAM,OAAO,KAAa,MAA+B,aAAuC;AAC9F,UAAM,SAAS,MAAM,SAAS,IAAI;AAClC,SAAK,MAAM,IAAI,KAAK,EAAE,MAAM,QAAQ,YAAY,CAAC;AACjD,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,SAAS,KAA8B;AAC3C,UAAM,QAAQ,KAAK,MAAM,IAAI,GAAG;AAChC,QAAI,CAAC,OAAO;AACV,YAAM,IAAI,MAAM,4BAA4B,GAAG,EAAE;AAAA,IACnD;AACA,WAAO,MAAM;AAAA,EACf;AAAA,EAEA,MAAM,OAAO,KAA4B;AACvC,QAAI,CAAC,KAAK,MAAM,IAAI,GAAG,GAAG;AACxB,YAAM,IAAI,MAAM,4BAA4B,GAAG,EAAE;AAAA,IACnD;AACA,SAAK,MAAM,OAAO,GAAG;AAAA,EACvB;AAAA,EAEA,MAAM,OAAO,KAAa,mBAA6C;AACrE,QAAI,CAAC,KAAK,MAAM,IAAI,GAAG,GAAG;AACxB,YAAM,IAAI,MAAM,4BAA4B,GAAG,EAAE;AAAA,IACnD;AACA,WAAO,YAAY,GAAG;AAAA,EACxB;AAAA,EAEA,MAAM,OAAO,KAA+B;AAC1C,WAAO,KAAK,MAAM,IAAI,GAAG;AAAA,EAC3B;AAAA,EAEA,MAAM,KAAK,QAAoC;AAC7C,UAAM,OAAO,MAAM,KAAK,KAAK,MAAM,KAAK,CAAC;AACzC,QAAI,WAAW,OAAW,QAAO;AACjC,WAAO,KAAK,OAAO,CAAC,MAAM,EAAE,WAAW,MAAM,CAAC;AAAA,EAChD;AAAA,EAEA,MAAM,eAAe,KAAsC;AACzD,UAAM,SAAS,MAAM,KAAK,SAAS,GAAG;AACtC,WAAO,IAAI,eAA2B;AAAA,MACpC,MAAM,YAAY;AAChB,mBAAW,QAAQ,IAAI,WAAW,MAAM,CAAC;AACzC,mBAAW,MAAM;AAAA,MACnB;AAAA,IACF,CAAC;AAAA,EACH;AAAA;AAAA,EAGA,QAAc;AACZ,SAAK,MAAM,MAAM;AAAA,EACnB;AAAA;AAAA,EAGA,OAAe;AACb,WAAO,KAAK,MAAM;AAAA,EACpB;AACF;;;ACrEO,IAAM,UAAU,uBAAO,SAAS;;;AJ+BhC,IAAM,gBAAN,MAAoB;AAAA,EACzB,OAAO,QAAQ,UAAgC,EAAE,SAAS,QAAQ,GAAkB;AAClF,UAAM,WACJ,QAAQ,YAAY,UAChB;AAAA,MACE,SAAS;AAAA,MACT,YAAY,MAAM,IAAI,oBAAoB,QAAQ,YAAY,WAAW;AAAA,IAC3E,IACA;AAAA,MACE,SAAS;AAAA,MACT,UAAU;AAAA,IACZ;AAEN,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,QAAQ;AAAA,MACR,WAAW,CAAC,QAAQ;AAAA,MACpB,SAAS,CAAC,OAAO;AAAA,IACnB;AAAA,EACF;AACF;AApBa,gBAAN;AAAA,EADN,OAAO,CAAC,CAAC;AAAA,GACG;","names":[]}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage subsystem — protocol (port)
|
|
3
|
+
*
|
|
4
|
+
* IStorageService is the hexagonal port. Use cases inject this interface via
|
|
5
|
+
* STORAGE token. They never depend on a specific backend implementation.
|
|
6
|
+
*
|
|
7
|
+
* All methods throw on failure — callers must handle upload/download errors
|
|
8
|
+
* explicitly. There is no null-return behavior like CacheService.
|
|
9
|
+
*
|
|
10
|
+
* Users who need cloud storage (S3, GCS, R2) implement this interface
|
|
11
|
+
* directly. No Drizzle backend exists — files in Postgres is an antipattern.
|
|
12
|
+
*/
|
|
13
|
+
interface IStorageService {
|
|
14
|
+
/**
|
|
15
|
+
* Upload a file and return the stored key (same as the input key).
|
|
16
|
+
*
|
|
17
|
+
* @param key - Storage key / path (e.g. 'avatars/user-123.png')
|
|
18
|
+
* @param data - File contents as a Buffer or a ReadableStream
|
|
19
|
+
* @param contentType - Optional MIME type (e.g. 'image/png')
|
|
20
|
+
* @returns The stored key
|
|
21
|
+
* @throws On any write failure
|
|
22
|
+
*/
|
|
23
|
+
upload(key: string, data: Buffer | ReadableStream, contentType?: string): Promise<string>;
|
|
24
|
+
/**
|
|
25
|
+
* Download a file by key and return its contents as a Buffer.
|
|
26
|
+
*
|
|
27
|
+
* @throws If the file does not exist or cannot be read
|
|
28
|
+
*/
|
|
29
|
+
download(key: string): Promise<Buffer>;
|
|
30
|
+
/**
|
|
31
|
+
* Delete a file by key.
|
|
32
|
+
*
|
|
33
|
+
* @throws If the file does not exist or cannot be deleted
|
|
34
|
+
*/
|
|
35
|
+
delete(key: string): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Return a URL for accessing the file.
|
|
38
|
+
*
|
|
39
|
+
* For local backend: returns a `file://` URI.
|
|
40
|
+
* For cloud backends: returns a presigned URL that expires after `expiresInSeconds`.
|
|
41
|
+
*
|
|
42
|
+
* @param key - Storage key
|
|
43
|
+
* @param expiresInSeconds - URL expiry (ignored by local/memory backends)
|
|
44
|
+
* @throws If the file does not exist
|
|
45
|
+
*/
|
|
46
|
+
getUrl(key: string, expiresInSeconds?: number): Promise<string>;
|
|
47
|
+
/**
|
|
48
|
+
* Check whether a file exists at the given key.
|
|
49
|
+
*
|
|
50
|
+
* @returns `true` if the file exists, `false` otherwise
|
|
51
|
+
* @throws Only on unexpected I/O errors (not on simple absence)
|
|
52
|
+
*/
|
|
53
|
+
exists(key: string): Promise<boolean>;
|
|
54
|
+
/**
|
|
55
|
+
* List all stored keys, optionally filtered by prefix.
|
|
56
|
+
*
|
|
57
|
+
* @param prefix - Optional prefix filter (e.g. 'avatars/')
|
|
58
|
+
* @returns Array of keys matching the prefix (or all keys if omitted)
|
|
59
|
+
*/
|
|
60
|
+
list(prefix?: string): Promise<string[]>;
|
|
61
|
+
/**
|
|
62
|
+
* Download a file by key and return its contents as a Web ReadableStream.
|
|
63
|
+
*
|
|
64
|
+
* @throws If the file does not exist or cannot be read
|
|
65
|
+
*/
|
|
66
|
+
downloadStream(key: string): Promise<ReadableStream>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export type { IStorageService };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=storage.protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../runtime/subsystems/storage/storage.tokens.ts"],"sourcesContent":["/**\n * Injection token for the storage service.\n *\n * Usage in use cases:\n * ```typescript\n * constructor(@Inject(STORAGE) private readonly storage: IStorageService) {}\n * ```\n */\nexport const STORAGE = Symbol('STORAGE');\n"],"mappings":";AAQO,IAAM,UAAU,uBAAO,SAAS;","names":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// runtime/subsystems/storage/storage.utils.ts
|
|
2
|
+
async function toBuffer(data) {
|
|
3
|
+
if (Buffer.isBuffer(data)) {
|
|
4
|
+
return data;
|
|
5
|
+
}
|
|
6
|
+
const reader = data.getReader();
|
|
7
|
+
const chunks = [];
|
|
8
|
+
while (true) {
|
|
9
|
+
const { done, value } = await reader.read();
|
|
10
|
+
if (done) break;
|
|
11
|
+
if (value) chunks.push(value);
|
|
12
|
+
}
|
|
13
|
+
return Buffer.concat(chunks);
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
toBuffer
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=storage.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../runtime/subsystems/storage/storage.utils.ts"],"sourcesContent":["/**\n * Storage subsystem — shared utilities\n */\n\n/**\n * Convert a Buffer or Web ReadableStream to a Node.js Buffer.\n */\nexport async function toBuffer(data: Buffer | ReadableStream): Promise<Buffer> {\n if (Buffer.isBuffer(data)) {\n return data;\n }\n const reader = (data as ReadableStream<Uint8Array>).getReader();\n const chunks: Uint8Array[] = [];\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n if (value) chunks.push(value);\n }\n return Buffer.concat(chunks);\n}\n"],"mappings":";AAOA,eAAsB,SAAS,MAAgD;AAC7E,MAAI,OAAO,SAAS,IAAI,GAAG;AACzB,WAAO;AAAA,EACT;AACA,QAAM,SAAU,KAAoC,UAAU;AAC9D,QAAM,SAAuB,CAAC;AAC9B,SAAO,MAAM;AACX,UAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,QAAI,KAAM;AACV,QAAI,MAAO,QAAO,KAAK,KAAK;AAAA,EAC9B;AACA,SAAO,OAAO,OAAO,MAAM;AAC7B;","names":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* DrizzleClient type alias
|
|
5
|
+
*
|
|
6
|
+
* Type alias for the Drizzle ORM database client. Using NodePgDatabase
|
|
7
|
+
* as the canonical Drizzle Postgres client type.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The Drizzle database client type used throughout the application.
|
|
12
|
+
* Typed with a permissive schema to allow use in the abstract base class
|
|
13
|
+
* without coupling to a specific schema module.
|
|
14
|
+
*/
|
|
15
|
+
type DrizzleClient = NodePgDatabase<any>;
|
|
16
|
+
|
|
17
|
+
export type { DrizzleClient };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=drizzle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|