appos 0.3.5-0 → 0.3.7-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/dist/bin/main.mjs +3 -3
- package/dist/bin/youch-handler-D7REmh8Z.mjs +2 -0
- package/dist/exports/api/adapter-C2mMJKvG.mjs +1504 -0
- package/dist/exports/api/{auth-schema.mjs → auth-schema-CON4yFFY.mjs} +2 -3
- package/dist/exports/api/bun-sqlite-dialect-CPpPZa23.mjs +155 -0
- package/dist/exports/{cli/_virtual/rolldown_runtime.mjs → api/chunk-CyXqrcp_.mjs} +14 -1
- package/dist/exports/api/conditions-DjBAWfiK.mjs +116 -0
- package/dist/exports/api/dialect-CUUD24Ge.mjs +72 -0
- package/dist/exports/api/env-CwT3zhez.mjs +1 -0
- package/dist/exports/api/esm-_hkVMulx.mjs +15816 -0
- package/dist/exports/api/event-BHFSE6hY.mjs +20983 -0
- package/dist/exports/api/extract-blob-metadata-BMgUEPcW.mjs +4 -0
- package/dist/exports/api/extract-blob-metadata-_9RUEwoU.mjs +9818 -0
- package/dist/exports/api/generate-image-variant-DOIzj1wJ.mjs +4 -0
- package/dist/exports/api/generate-image-variant-DxOPoGAk.mjs +118 -0
- package/dist/exports/api/generate-preview-CvTFuq58.mjs +160 -0
- package/dist/exports/api/generate-preview-Dk3coswZ.mjs +4 -0
- package/dist/exports/api/index.d.mts +7347 -20
- package/dist/exports/api/index.mjs +146856 -18
- package/dist/exports/api/kysely-adapter-CmP2TbkS.mjs +296 -0
- package/dist/exports/api/memory-adapter-BzhRhLFK.mjs +212 -0
- package/dist/exports/api/node-sqlite-dialect-Bl5suBxl.mjs +155 -0
- package/dist/exports/api/orm-CMqufD21.mjs +153690 -0
- package/dist/exports/api/orm-DXqYuKvB.d.mts +11 -0
- package/dist/exports/api/orm.d.mts +2 -11
- package/dist/exports/api/orm.mjs +4 -42
- package/dist/exports/api/pdf-YxB2Hm1p.mjs +25822 -0
- package/dist/exports/api/purge-attachment-Cf6KH2Jv.mjs +34 -0
- package/dist/exports/api/purge-attachment-DIuil7ps.mjs +4 -0
- package/dist/exports/{cli/api/workflows/purge-audit-logs.mjs → api/purge-audit-logs-z6j_Pu47.mjs} +3 -3
- package/dist/exports/{cli/api/workflows/purge-unattached-blobs.mjs → api/purge-unattached-blobs-B0TfY5Hk.mjs} +1 -1
- package/dist/exports/api/react-BYhV5bYt.mjs +1131 -0
- package/dist/exports/api/server.node-DyVrQ6cz.mjs +19298 -0
- package/dist/exports/api/table-6bTIEqON.mjs +2636 -0
- package/dist/exports/api/{workflows/track-db-changes.mjs → track-db-changes-BysaV6nN.mjs} +14 -14
- package/dist/exports/api/{workflow.mjs → workflow-BuSWHcX-.mjs} +121 -10
- package/dist/exports/api/workflows/auth-schema-BFve3hgZ.mjs +2813 -0
- package/dist/exports/api/workflows/{_virtual/rolldown_runtime.mjs → chunk-B36mNPO4.mjs} +5 -1
- package/dist/exports/api/workflows/extract-blob-metadata-BcWKvY2K.mjs +9818 -0
- package/dist/exports/{cli/api/workflows/generate-image-variant.mjs → api/workflows/generate-image-variant-BAFvL_zV.mjs} +20 -20
- package/dist/exports/{cli/api/workflows/generate-preview.mjs → api/workflows/generate-preview-BjlIVYYp.mjs} +6 -6
- package/dist/exports/api/workflows/index.d.mts +2011 -1
- package/dist/exports/api/workflows/index.mjs +2 -1
- package/dist/exports/api/workflows/pdf-DUB8zyIc.mjs +25822 -0
- package/dist/exports/{cli/api/workflows/purge-attachment.mjs → api/workflows/purge-attachment-k_sdxTPY.mjs} +3 -3
- package/dist/exports/api/workflows/{purge-audit-logs.mjs → purge-audit-logs-zCyWj4Mw.mjs} +12 -3
- package/dist/exports/api/workflows/{purge-unattached-blobs.mjs → purge-unattached-blobs-CdsuFAeW.mjs} +1 -1
- package/dist/exports/api/workflows/track-db-changes-CiKaI9gT.mjs +20943 -0
- package/dist/exports/api/workflows/track-db-changes-DEWQYryO.mjs +4 -0
- package/dist/exports/{cli/api/workflow.mjs → api/workflows/workflow-BjM2xCa6.mjs} +23 -3
- package/dist/exports/api/workflows/zod-Br0enFWK.mjs +12333 -0
- package/dist/exports/api/zod-CdrJdBtV.mjs +12571 -0
- package/dist/exports/cli/auth-schema-CNuOqPi-.mjs +2813 -0
- package/dist/exports/{api/_virtual/rolldown_runtime.mjs → cli/chunk-B36mNPO4.mjs} +5 -1
- package/dist/exports/cli/extract-blob-metadata-CV1Ke90d.mjs +9818 -0
- package/dist/exports/{api/workflows/generate-image-variant.mjs → cli/generate-image-variant-CM1BrVvZ.mjs} +20 -20
- package/dist/exports/{api/workflows/generate-preview.mjs → cli/generate-preview-DdHQ3ukz.mjs} +6 -6
- package/dist/exports/cli/index.d.mts +2142 -2
- package/dist/exports/cli/index.mjs +41 -1
- package/dist/exports/cli/pdf-CLUPEIdT.mjs +25822 -0
- package/dist/exports/{api/workflows/purge-attachment.mjs → cli/purge-attachment-Dc_J74dG.mjs} +3 -3
- package/dist/exports/cli/purge-audit-logs-DFhWh-Bx.mjs +56 -0
- package/dist/exports/cli/purge-unattached-blobs-C1MRlM_2.mjs +46 -0
- package/dist/exports/cli/track-db-changes-CfneOF2_.mjs +20943 -0
- package/dist/exports/{api/workflows/api/workflow.mjs → cli/workflow-DSbbXBMt.mjs} +23 -3
- package/dist/exports/cli/zod-7q0_Mtnn.mjs +12333 -0
- package/dist/exports/tests/api.d.mts +7354 -5
- package/dist/exports/tests/api.mjs +79 -1
- package/dist/exports/tests/auth-schema-B_qHPoa4.mjs +1 -0
- package/dist/exports/tests/chunk-Cii4FAhs.mjs +1 -0
- package/dist/exports/tests/conditions-BeWxRN_Z.mjs +1 -0
- package/dist/exports/tests/constants-D_m07gCJ.mjs +1 -0
- package/dist/exports/tests/dist-Cx2HEBOB.mjs +296 -0
- package/dist/exports/tests/dist-DnACOvNW.mjs +7 -0
- package/dist/exports/tests/extract-blob-metadata-6xQrarjB.mjs +169 -0
- package/dist/exports/tests/generate-image-variant-KQITLmCx.mjs +1 -0
- package/dist/exports/tests/generate-preview-YnujQo5I.mjs +1 -0
- package/dist/exports/tests/mock-BvoS23fi.mjs +1 -0
- package/dist/exports/tests/mock.mjs +1 -1
- package/dist/exports/tests/pdf-lZ-as2o7.mjs +13 -0
- package/dist/exports/tests/purge-attachment-DTSmCl-z.mjs +1 -0
- package/dist/exports/tests/purge-audit-logs-D0_UUhN2.mjs +1 -0
- package/dist/exports/tests/purge-unattached-blobs-IENmSB8K.mjs +1 -0
- package/dist/exports/tests/react.mjs +6 -1
- package/dist/exports/tests/setup.d.mts +1 -1
- package/dist/exports/tests/setup.mjs +34 -1
- package/dist/exports/tests/table-CmPSf_pE.mjs +1 -0
- package/dist/exports/tests/track-db-changes-Td9Q3DLd.mjs +1 -0
- package/dist/exports/tests/{api/workflow.mjs → workflow-BWRWyC83.mjs} +1 -1
- package/dist/exports/tests/youch-handler-efUxKCCs.mjs +1 -0
- package/dist/exports/tests/zod-CkJO9qpV.mjs +23 -0
- package/dist/exports/vendors/date.js +13236 -1
- package/dist/exports/vendors/toolkit.js +2206 -1
- package/dist/exports/vendors/zod.js +12344 -1
- package/dist/exports/vite/index.d.mts +1 -1
- package/dist/exports/vite/index.mjs +26 -1
- package/dist/exports/vite/lib-B0s0q6aX.mjs +382 -0
- package/dist/exports/vite/lib-BkrbWMaV.mjs +1 -0
- package/dist/exports/web/browser-ponyfill-DxTJMXNq.js +443 -0
- package/dist/exports/web/chunk-DksrlJLg.js +49 -0
- package/dist/exports/web/index.d.ts +2546 -2
- package/dist/exports/web/index.js +9295 -6
- package/dist/exports/web/plugin-DqTFWG7p.js +250 -0
- package/package.json +1 -7
- package/dist/bin/youch-handler-DrYdbUhe.mjs +0 -2
- package/dist/exports/api/app-context.d.mts +0 -115
- package/dist/exports/api/app-context.mjs +0 -24
- package/dist/exports/api/auth-schema.d.mts +0 -4248
- package/dist/exports/api/auth.d.mts +0 -402
- package/dist/exports/api/auth.mjs +0 -188
- package/dist/exports/api/cache.d.mts +0 -44
- package/dist/exports/api/cache.mjs +0 -28
- package/dist/exports/api/config.d.mts +0 -28
- package/dist/exports/api/config.mjs +0 -72
- package/dist/exports/api/constants.mjs +0 -92
- package/dist/exports/api/container.d.mts +0 -210
- package/dist/exports/api/container.mjs +0 -49
- package/dist/exports/api/database.d.mts +0 -101
- package/dist/exports/api/database.mjs +0 -219
- package/dist/exports/api/event.d.mts +0 -235
- package/dist/exports/api/event.mjs +0 -236
- package/dist/exports/api/i18n.d.mts +0 -34
- package/dist/exports/api/i18n.mjs +0 -45
- package/dist/exports/api/instrumentation.d.mts +0 -7
- package/dist/exports/api/instrumentation.mjs +0 -40
- package/dist/exports/api/logger.d.mts +0 -21
- package/dist/exports/api/logger.mjs +0 -26
- package/dist/exports/api/mailer.d.mts +0 -70
- package/dist/exports/api/mailer.mjs +0 -37
- package/dist/exports/api/middleware/request-logger.d.mts +0 -24
- package/dist/exports/api/middleware.d.mts +0 -39
- package/dist/exports/api/middleware.mjs +0 -73
- package/dist/exports/api/openapi.d.mts +0 -271
- package/dist/exports/api/openapi.mjs +0 -507
- package/dist/exports/api/otel.d.mts +0 -40
- package/dist/exports/api/otel.mjs +0 -56
- package/dist/exports/api/redis.d.mts +0 -34
- package/dist/exports/api/redis.mjs +0 -41
- package/dist/exports/api/storage-schema.d.mts +0 -707
- package/dist/exports/api/storage-schema.mjs +0 -72
- package/dist/exports/api/storage.d.mts +0 -506
- package/dist/exports/api/storage.mjs +0 -833
- package/dist/exports/api/web/auth.mjs +0 -17
- package/dist/exports/api/workflow.d.mts +0 -250
- package/dist/exports/api/workflows/api/auth-schema.mjs +0 -373
- package/dist/exports/api/workflows/api/auth.d.mts +0 -379
- package/dist/exports/api/workflows/api/cache.d.mts +0 -44
- package/dist/exports/api/workflows/api/config.d.mts +0 -18
- package/dist/exports/api/workflows/api/container.d.mts +0 -167
- package/dist/exports/api/workflows/api/database.d.mts +0 -47
- package/dist/exports/api/workflows/api/event.d.mts +0 -68
- package/dist/exports/api/workflows/api/event.mjs +0 -126
- package/dist/exports/api/workflows/api/logger.d.mts +0 -21
- package/dist/exports/api/workflows/api/mailer.d.mts +0 -70
- package/dist/exports/api/workflows/api/orm.d.mts +0 -13
- package/dist/exports/api/workflows/api/redis.mjs +0 -3
- package/dist/exports/api/workflows/api/storage-schema.d.mts +0 -699
- package/dist/exports/api/workflows/api/storage.d.mts +0 -396
- package/dist/exports/api/workflows/api/workflow.d.mts +0 -24
- package/dist/exports/api/workflows/constants.mjs +0 -23
- package/dist/exports/api/workflows/extract-blob-metadata.mjs +0 -132
- package/dist/exports/api/workflows/generate-image-variant.d.mts +0 -63
- package/dist/exports/api/workflows/track-db-changes.d.mts +0 -72
- package/dist/exports/cli/api/auth-schema.mjs +0 -373
- package/dist/exports/cli/api/auth.d.mts +0 -379
- package/dist/exports/cli/api/cache.d.mts +0 -44
- package/dist/exports/cli/api/config.d.mts +0 -18
- package/dist/exports/cli/api/container.d.mts +0 -167
- package/dist/exports/cli/api/database.d.mts +0 -47
- package/dist/exports/cli/api/event.d.mts +0 -68
- package/dist/exports/cli/api/event.mjs +0 -126
- package/dist/exports/cli/api/logger.d.mts +0 -21
- package/dist/exports/cli/api/mailer.d.mts +0 -70
- package/dist/exports/cli/api/orm.d.mts +0 -13
- package/dist/exports/cli/api/redis.mjs +0 -3
- package/dist/exports/cli/api/storage-schema.d.mts +0 -699
- package/dist/exports/cli/api/storage.d.mts +0 -396
- package/dist/exports/cli/api/workflow.d.mts +0 -2
- package/dist/exports/cli/api/workflows/extract-blob-metadata.mjs +0 -132
- package/dist/exports/cli/api/workflows/generate-image-variant.d.mts +0 -63
- package/dist/exports/cli/api/workflows/track-db-changes.mjs +0 -110
- package/dist/exports/cli/command.d.mts +0 -56
- package/dist/exports/cli/command.mjs +0 -43
- package/dist/exports/cli/constants.mjs +0 -23
- package/dist/exports/cli/context.d.mts +0 -170
- package/dist/exports/devtools/index.d.ts +0 -3
- package/dist/exports/devtools/index.js +0 -4
- package/dist/exports/tests/_virtual/rolldown_runtime.mjs +0 -1
- package/dist/exports/tests/api/app-context.d.mts +0 -115
- package/dist/exports/tests/api/app-context.mjs +0 -1
- package/dist/exports/tests/api/auth-schema.d.mts +0 -4248
- package/dist/exports/tests/api/auth-schema.mjs +0 -1
- package/dist/exports/tests/api/auth.d.mts +0 -402
- package/dist/exports/tests/api/cache.d.mts +0 -44
- package/dist/exports/tests/api/config.d.mts +0 -28
- package/dist/exports/tests/api/container.d.mts +0 -210
- package/dist/exports/tests/api/database.d.mts +0 -101
- package/dist/exports/tests/api/database.mjs +0 -1
- package/dist/exports/tests/api/event.d.mts +0 -235
- package/dist/exports/tests/api/event.mjs +0 -1
- package/dist/exports/tests/api/i18n.d.mts +0 -34
- package/dist/exports/tests/api/index.d.mts +0 -26
- package/dist/exports/tests/api/logger.d.mts +0 -21
- package/dist/exports/tests/api/mailer.d.mts +0 -70
- package/dist/exports/tests/api/middleware/error-handler.mjs +0 -1
- package/dist/exports/tests/api/middleware/health.mjs +0 -1
- package/dist/exports/tests/api/middleware/i18n.mjs +0 -1
- package/dist/exports/tests/api/middleware/request-logger.d.mts +0 -24
- package/dist/exports/tests/api/middleware/request-logger.mjs +0 -1
- package/dist/exports/tests/api/middleware/shutdown.mjs +0 -1
- package/dist/exports/tests/api/middleware/timeout.mjs +0 -1
- package/dist/exports/tests/api/middleware/youch-handler.mjs +0 -1
- package/dist/exports/tests/api/middleware.d.mts +0 -39
- package/dist/exports/tests/api/middleware.mjs +0 -1
- package/dist/exports/tests/api/openapi.d.mts +0 -271
- package/dist/exports/tests/api/openapi.mjs +0 -1
- package/dist/exports/tests/api/orm.d.mts +0 -13
- package/dist/exports/tests/api/otel.d.mts +0 -40
- package/dist/exports/tests/api/redis.d.mts +0 -34
- package/dist/exports/tests/api/redis.mjs +0 -1
- package/dist/exports/tests/api/server.mjs +0 -1
- package/dist/exports/tests/api/storage-schema.d.mts +0 -707
- package/dist/exports/tests/api/storage.d.mts +0 -506
- package/dist/exports/tests/api/workflow.d.mts +0 -250
- package/dist/exports/tests/api/workflows/extract-blob-metadata.mjs +0 -1
- package/dist/exports/tests/api/workflows/generate-image-variant.d.mts +0 -63
- package/dist/exports/tests/api/workflows/generate-image-variant.mjs +0 -1
- package/dist/exports/tests/api/workflows/generate-preview.mjs +0 -1
- package/dist/exports/tests/api/workflows/purge-attachment.mjs +0 -1
- package/dist/exports/tests/api/workflows/purge-audit-logs.mjs +0 -1
- package/dist/exports/tests/api/workflows/purge-unattached-blobs.mjs +0 -1
- package/dist/exports/tests/api/workflows/track-db-changes.mjs +0 -1
- package/dist/exports/tests/constants.mjs +0 -1
- package/dist/exports/tests/instrumentation.d.mts +0 -7
- package/dist/exports/tests/instrumentation.mjs +0 -1
- package/dist/exports/web/api/auth.d.ts +0 -125
- package/dist/exports/web/api/database.d.ts +0 -4
- package/dist/exports/web/api/logger.d.ts +0 -1
- package/dist/exports/web/auth.d.ts +0 -2388
- package/dist/exports/web/auth.js +0 -75
- package/dist/exports/web/i18n.d.ts +0 -42
- package/dist/exports/web/i18n.js +0 -45
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
|
|
3
|
-
//#region src/api/config.ts
|
|
4
|
-
/**
|
|
5
|
-
* The config base schema.
|
|
6
|
-
*/
|
|
7
|
-
const baseSchema = z.object({
|
|
8
|
-
APP_NAME: z.string().default("AppOS"),
|
|
9
|
-
APP_DESC: z.string().default("The app operating system to build your business."),
|
|
10
|
-
APP_VERSION: z.string().default("development")
|
|
11
|
-
});
|
|
12
|
-
/**
|
|
13
|
-
* Expands variables in environment values using {{VAR_NAME}} syntax.
|
|
14
|
-
* Supports nested expansion and handles circular references.
|
|
15
|
-
*
|
|
16
|
-
* If a variable is not found, the placeholder is preserved in the output.
|
|
17
|
-
* Variables can reference other variables recursively.
|
|
18
|
-
*
|
|
19
|
-
* @param env Environment variables object
|
|
20
|
-
* @returns Environment variables with expanded values
|
|
21
|
-
*/
|
|
22
|
-
function expandVariables(env) {
|
|
23
|
-
const expanded = { ...env };
|
|
24
|
-
const expanding = /* @__PURE__ */ new Set();
|
|
25
|
-
function expand(key, value) {
|
|
26
|
-
if (expanding.has(key)) throw new Error(`Circular reference detected in environment variable: ${key}`);
|
|
27
|
-
expanding.add(key);
|
|
28
|
-
const result = value.replace(/\{\{([^}]+)\}\}/g, (match, varName) => {
|
|
29
|
-
const trimmedVarName = varName.trim();
|
|
30
|
-
if (!trimmedVarName) return match;
|
|
31
|
-
const varValue = expanded[trimmedVarName];
|
|
32
|
-
if (varValue === void 0) return match;
|
|
33
|
-
if (varValue.includes("{{")) return expand(trimmedVarName, varValue);
|
|
34
|
-
return varValue;
|
|
35
|
-
});
|
|
36
|
-
expanding.delete(key);
|
|
37
|
-
return result;
|
|
38
|
-
}
|
|
39
|
-
for (const [key, value] of Object.entries(expanded)) if (value?.includes("{{")) expanded[key] = expand(key, value);
|
|
40
|
-
return expanded;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Creates a configuration object by merging base config with user-defined schema.
|
|
44
|
-
*
|
|
45
|
-
* Variables in default values are expanded after defaults are applied.
|
|
46
|
-
* For example: `DATABASE_URL: z.string().default("postgres://{{DB_HOST}}:5432")`
|
|
47
|
-
*
|
|
48
|
-
* @param userSchema User-defined Zod schema to merge with base config.
|
|
49
|
-
* @returns Parsed and validated configuration object.
|
|
50
|
-
*/
|
|
51
|
-
function defineConfig(userSchema) {
|
|
52
|
-
const mergedSchema = baseSchema.extend(userSchema.shape);
|
|
53
|
-
const defaults = {};
|
|
54
|
-
for (const [key, fieldSchema] of Object.entries(mergedSchema.shape)) {
|
|
55
|
-
let current = fieldSchema;
|
|
56
|
-
while (current) {
|
|
57
|
-
const def = current.def;
|
|
58
|
-
if (def.defaultValue !== void 0) {
|
|
59
|
-
const defaultValue = typeof def.defaultValue === "function" ? def.defaultValue() : def.defaultValue;
|
|
60
|
-
if (typeof defaultValue === "string") defaults[key] = defaultValue;
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
current = def.innerType || def.schema;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
const merged = { ...defaults };
|
|
67
|
-
for (const [key, value] of Object.entries(process.env)) if (value !== void 0) merged[key] = value;
|
|
68
|
-
return mergedSchema.parse(expandVariables(merged));
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
//#endregion
|
|
72
|
-
export { baseSchema, defineConfig };
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
//#region src/constants.ts
|
|
2
|
-
/**
|
|
3
|
-
* Directory constants used throughout the AppOS framework.
|
|
4
|
-
*
|
|
5
|
-
* These constants define the conventional directory structure for AppOS applications.
|
|
6
|
-
* All paths are relative to the project root unless otherwise specified.
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* The main AppOS directory containing application code.
|
|
10
|
-
*
|
|
11
|
-
* Expected structure:
|
|
12
|
-
* - `<project-root>/api/container.ts` - Application container definition
|
|
13
|
-
* - `<project-root>/api/commands/` - CLI commands
|
|
14
|
-
* - `<project-root>/api/databases/` - Database schemas and migrations
|
|
15
|
-
* - `<project-root>/api/emails/` - Email templates
|
|
16
|
-
* - `<project-root>/api/events/` - Event definitions
|
|
17
|
-
* - `<project-root>/api/middleware/` - Custom middleware
|
|
18
|
-
* - `<project-root>/api/routes/` - API routes
|
|
19
|
-
* - `<project-root>/api/workflows/` - Background workflows
|
|
20
|
-
*
|
|
21
|
-
* @default "api"
|
|
22
|
-
*/
|
|
23
|
-
const APPOS_DIR = "api";
|
|
24
|
-
/**
|
|
25
|
-
* Directory for database schemas and migrations.
|
|
26
|
-
*
|
|
27
|
-
* Expected structure:
|
|
28
|
-
* - `<APPOS_DIR>/databases/<db-name>/schema.ts` - Database schema
|
|
29
|
-
* - `<APPOS_DIR>/databases/<db-name>/schema-migrations/` - Migration files
|
|
30
|
-
*
|
|
31
|
-
* @default "databases"
|
|
32
|
-
*/
|
|
33
|
-
const DATABASES_DIR = "databases";
|
|
34
|
-
/**
|
|
35
|
-
* Directory for API route handlers.
|
|
36
|
-
*
|
|
37
|
-
* Expected structure:
|
|
38
|
-
* - `<APPOS_DIR>/routes/<route-name>.ts` - Route handler files
|
|
39
|
-
*
|
|
40
|
-
* @default "routes"
|
|
41
|
-
*/
|
|
42
|
-
const ROUTES_DIR = "routes";
|
|
43
|
-
/**
|
|
44
|
-
* Directory for background workflow definitions.
|
|
45
|
-
*
|
|
46
|
-
* Expected structure:
|
|
47
|
-
* - `<APPOS_DIR>/workflows/<workflow-name>.ts` - Workflow files
|
|
48
|
-
*
|
|
49
|
-
* @default "workflows"
|
|
50
|
-
*/
|
|
51
|
-
const WORKFLOWS_DIR = "workflows";
|
|
52
|
-
/**
|
|
53
|
-
* Directory for event definitions and subscriptions.
|
|
54
|
-
*
|
|
55
|
-
* Expected structure:
|
|
56
|
-
* - `<APPOS_DIR>/events/<event-name>.ts` - Event definition files
|
|
57
|
-
* - `<APPOS_DIR>/events/<subscription-name>.ts` - Event subscription files
|
|
58
|
-
*
|
|
59
|
-
* @default "events"
|
|
60
|
-
*/
|
|
61
|
-
const EVENTS_DIR = "events";
|
|
62
|
-
/**
|
|
63
|
-
* Directory for public static assets.
|
|
64
|
-
*
|
|
65
|
-
* Expected structure:
|
|
66
|
-
* - `<project-root>/public/` - Public directory root
|
|
67
|
-
* - `<project-root>/public/locales/` - i18n translation files
|
|
68
|
-
*
|
|
69
|
-
* @default "public"
|
|
70
|
-
*/
|
|
71
|
-
const PUBLIC_DIR = process.env.NODE_ENV === "production" ? "client" : "public";
|
|
72
|
-
/**
|
|
73
|
-
* Directory for i18n locale/translation files (relative to PUBLIC_DIR).
|
|
74
|
-
*
|
|
75
|
-
* Expected structure:
|
|
76
|
-
* - `<PUBLIC_DIR>/locales/<lng>/<ns>.json` - Translation files
|
|
77
|
-
*
|
|
78
|
-
* @default "locales"
|
|
79
|
-
*/
|
|
80
|
-
const LOCALES_DIR = "locales";
|
|
81
|
-
/**
|
|
82
|
-
* File extension for code files based on environment.
|
|
83
|
-
*
|
|
84
|
-
* In development: `.ts` (TypeScript source files)
|
|
85
|
-
* In production: `.js` (bundled JavaScript files)
|
|
86
|
-
*
|
|
87
|
-
* @default "ts" in development, "js" in production
|
|
88
|
-
*/
|
|
89
|
-
const FILE_EXT = process.env.NODE_ENV === "production" ? "js" : "ts";
|
|
90
|
-
|
|
91
|
-
//#endregion
|
|
92
|
-
export { APPOS_DIR, DATABASES_DIR, EVENTS_DIR, FILE_EXT, LOCALES_DIR, PUBLIC_DIR, ROUTES_DIR, WORKFLOWS_DIR };
|
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
import { Logger } from "./logger.mjs";
|
|
2
|
-
import { Database } from "./database.mjs";
|
|
3
|
-
import { Auth } from "./auth.mjs";
|
|
4
|
-
import { Cache } from "./cache.mjs";
|
|
5
|
-
import { Config } from "./config.mjs";
|
|
6
|
-
import { EventBus } from "./event.mjs";
|
|
7
|
-
import { Mailer } from "./mailer.mjs";
|
|
8
|
-
import { Storage } from "./storage.mjs";
|
|
9
|
-
import { i18n } from "i18next";
|
|
10
|
-
import { CorsOptions } from "cors";
|
|
11
|
-
import { Options } from "express-rate-limit";
|
|
12
|
-
import { HelmetOptions } from "helmet";
|
|
13
|
-
|
|
14
|
-
//#region src/api/container.d.ts
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Server configuration for the HTTP server.
|
|
18
|
-
*/
|
|
19
|
-
interface ServerConfig {
|
|
20
|
-
/**
|
|
21
|
-
* The host address the server will bind to.
|
|
22
|
-
*
|
|
23
|
-
* @default "0.0.0.0"
|
|
24
|
-
*/
|
|
25
|
-
host?: string;
|
|
26
|
-
/**
|
|
27
|
-
* The port number the server will listen on.
|
|
28
|
-
*/
|
|
29
|
-
port: number;
|
|
30
|
-
/**
|
|
31
|
-
* Request timeout in milliseconds. Requests exceeding this duration
|
|
32
|
-
* will receive a 408 Request Timeout response.
|
|
33
|
-
*
|
|
34
|
-
* @default 30000
|
|
35
|
-
*/
|
|
36
|
-
timeout?: number;
|
|
37
|
-
/**
|
|
38
|
-
* Maximum request body size for JSON and URL-encoded payloads.
|
|
39
|
-
* Supports bytes.js format strings (e.g., "1mb", "500kb", "10mb").
|
|
40
|
-
*
|
|
41
|
-
* @default "1mb"
|
|
42
|
-
*/
|
|
43
|
-
bodyLimit?: string;
|
|
44
|
-
/**
|
|
45
|
-
* The path for the health check endpoint.
|
|
46
|
-
*
|
|
47
|
-
* @default "/health"
|
|
48
|
-
*/
|
|
49
|
-
healthPath?: string;
|
|
50
|
-
/**
|
|
51
|
-
* CORS configuration. Omit or set to undefined to disable.
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* cors: { origin: "https://example.com", credentials: true }
|
|
55
|
-
*/
|
|
56
|
-
cors?: CorsOptions;
|
|
57
|
-
/**
|
|
58
|
-
* Security headers configuration (via helmet). Omit or set to undefined to disable.
|
|
59
|
-
* Recommended for production deployments.
|
|
60
|
-
*
|
|
61
|
-
* @example
|
|
62
|
-
* helmet: { contentSecurityPolicy: false } // Enable with CSP disabled
|
|
63
|
-
* helmet: {} // Enable with all defaults
|
|
64
|
-
*/
|
|
65
|
-
helmet?: HelmetOptions;
|
|
66
|
-
/**
|
|
67
|
-
* Rate limiting configuration. Array of express-rate-limit options.
|
|
68
|
-
* Each config is applied as a separate middleware - use `skip` function for path-specific limits.
|
|
69
|
-
* Redis store is automatically configured if `redisUrl` is provided.
|
|
70
|
-
*
|
|
71
|
-
* @example
|
|
72
|
-
* // Global rate limit
|
|
73
|
-
* rateLimit: [{ windowMs: 60000, limit: 100 }]
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* // Path-specific rate limits
|
|
77
|
-
* rateLimit: [
|
|
78
|
-
* { windowMs: 900000, limit: 5, skip: (req) => !req.path.startsWith("/api/auth") },
|
|
79
|
-
* { windowMs: 60000, limit: 100 }, // Default for all other routes
|
|
80
|
-
* ]
|
|
81
|
-
*/
|
|
82
|
-
rateLimit?: Options[];
|
|
83
|
-
/**
|
|
84
|
-
* Redis URL for rate limiting store (for multi-instance deployments).
|
|
85
|
-
* Server auto-connects and cleans up on shutdown.
|
|
86
|
-
* If omitted, uses in-memory store (not suitable for production clusters).
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* redisUrl: "redis://localhost:6379"
|
|
90
|
-
*/
|
|
91
|
-
redisUrl?: string;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Worker configuration for the DBOS workflow worker.
|
|
95
|
-
*/
|
|
96
|
-
interface WorkerConfig {
|
|
97
|
-
/**
|
|
98
|
-
* The system database URL for DBOS.
|
|
99
|
-
*/
|
|
100
|
-
dbUrl: string;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* The base application container type that holds required services like
|
|
104
|
-
* config, databases, and caches.
|
|
105
|
-
*/
|
|
106
|
-
interface AppContainer<TDb extends Record<"primary", Database> & Record<string, Database> = Record<"primary", Database> & Record<string, Database>> {
|
|
107
|
-
/**
|
|
108
|
-
* The application auth configuration.
|
|
109
|
-
*/
|
|
110
|
-
auth: Auth<TDb>;
|
|
111
|
-
/**
|
|
112
|
-
* A map of caches available in the application.
|
|
113
|
-
*/
|
|
114
|
-
cache: Record<string, Cache>;
|
|
115
|
-
/**
|
|
116
|
-
* The application configuration.
|
|
117
|
-
*/
|
|
118
|
-
config: Config;
|
|
119
|
-
/**
|
|
120
|
-
* A map of databases available in the application.
|
|
121
|
-
*/
|
|
122
|
-
db: TDb;
|
|
123
|
-
/**
|
|
124
|
-
* The i18n instance for internationalization.
|
|
125
|
-
*/
|
|
126
|
-
i18n: i18n;
|
|
127
|
-
/**
|
|
128
|
-
* The logger instance for logging messages.
|
|
129
|
-
*/
|
|
130
|
-
logger: Logger;
|
|
131
|
-
/**
|
|
132
|
-
* The event bus for in-memory and Redis pub/sub messaging.
|
|
133
|
-
*/
|
|
134
|
-
eventBus: EventBus;
|
|
135
|
-
/**
|
|
136
|
-
* The mailer instance for sending emails.
|
|
137
|
-
*/
|
|
138
|
-
mailer: Mailer;
|
|
139
|
-
/**
|
|
140
|
-
* Server configuration for the HTTP server.
|
|
141
|
-
*/
|
|
142
|
-
server: ServerConfig;
|
|
143
|
-
/**
|
|
144
|
-
* A map of storage services available in the application.
|
|
145
|
-
*/
|
|
146
|
-
storage: Record<"primary", Storage> & Record<string, Storage>;
|
|
147
|
-
/**
|
|
148
|
-
* Worker configuration for the DBOS workflow worker.
|
|
149
|
-
*/
|
|
150
|
-
worker: WorkerConfig;
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Global namespace for user container augmentation.
|
|
154
|
-
* Users can extend Container interface in their container.ts file.
|
|
155
|
-
*/
|
|
156
|
-
declare global {
|
|
157
|
-
namespace AppOS {
|
|
158
|
-
interface Container {}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* The container type used throughout the application.
|
|
163
|
-
* Merges base AppContainer with user's custom Container augmentations.
|
|
164
|
-
*/
|
|
165
|
-
type Container = AppContainer & AppOS.Container;
|
|
166
|
-
/**
|
|
167
|
-
* Defines an application container with type-safe validation and inference.
|
|
168
|
-
*
|
|
169
|
-
* This helper function ensures that:
|
|
170
|
-
* 1. All required base fields (config, cache, db) are provided
|
|
171
|
-
* 2. Custom fields are fully preserved in the inferred type
|
|
172
|
-
* 3. TypeScript provides autocomplete for all fields in commands/routes
|
|
173
|
-
*
|
|
174
|
-
* @template T - The container type extending AppContainer
|
|
175
|
-
* @param container - The container object with required and custom fields
|
|
176
|
-
* @returns The same container object with full type inference
|
|
177
|
-
*
|
|
178
|
-
* @example
|
|
179
|
-
* ```typescript
|
|
180
|
-
* // In your api/main.ts file:
|
|
181
|
-
* export async function defineContainer() {
|
|
182
|
-
* const config = defineConfig(z.object({
|
|
183
|
-
* PORT: z.coerce.number().default(3000),
|
|
184
|
-
* EVENTS_DB_URL: z.string(),
|
|
185
|
-
* WORKER_DB_URL: z.string(),
|
|
186
|
-
* }));
|
|
187
|
-
* const logger = defineLogger({ level: config.LOG_LEVEL });
|
|
188
|
-
*
|
|
189
|
-
* return defineAppContainer({
|
|
190
|
-
* auth: defineAuth({ config }),
|
|
191
|
-
* cache: {},
|
|
192
|
-
* config,
|
|
193
|
-
* db: {},
|
|
194
|
-
* eventBus: defineEventBus({ dbUrl: config.EVENTS_DB_URL, logger }),
|
|
195
|
-
* i18n: await defineI18n({ ... }),
|
|
196
|
-
* logger,
|
|
197
|
-
* mailer: defineMailer({ ... }),
|
|
198
|
-
* server: {
|
|
199
|
-
* port: config.PORT,
|
|
200
|
-
* },
|
|
201
|
-
* worker: {
|
|
202
|
-
* dbUrl: config.WORKER_DB_URL,
|
|
203
|
-
* },
|
|
204
|
-
* });
|
|
205
|
-
* }
|
|
206
|
-
* ```
|
|
207
|
-
*/
|
|
208
|
-
declare function defineAppContainer<T extends AppContainer>(container: T): T;
|
|
209
|
-
//#endregion
|
|
210
|
-
export { AppContainer, Container, ServerConfig, WorkerConfig, defineAppContainer };
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
//#region src/api/container.ts
|
|
2
|
-
/**
|
|
3
|
-
* Defines an application container with type-safe validation and inference.
|
|
4
|
-
*
|
|
5
|
-
* This helper function ensures that:
|
|
6
|
-
* 1. All required base fields (config, cache, db) are provided
|
|
7
|
-
* 2. Custom fields are fully preserved in the inferred type
|
|
8
|
-
* 3. TypeScript provides autocomplete for all fields in commands/routes
|
|
9
|
-
*
|
|
10
|
-
* @template T - The container type extending AppContainer
|
|
11
|
-
* @param container - The container object with required and custom fields
|
|
12
|
-
* @returns The same container object with full type inference
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* // In your api/main.ts file:
|
|
17
|
-
* export async function defineContainer() {
|
|
18
|
-
* const config = defineConfig(z.object({
|
|
19
|
-
* PORT: z.coerce.number().default(3000),
|
|
20
|
-
* EVENTS_DB_URL: z.string(),
|
|
21
|
-
* WORKER_DB_URL: z.string(),
|
|
22
|
-
* }));
|
|
23
|
-
* const logger = defineLogger({ level: config.LOG_LEVEL });
|
|
24
|
-
*
|
|
25
|
-
* return defineAppContainer({
|
|
26
|
-
* auth: defineAuth({ config }),
|
|
27
|
-
* cache: {},
|
|
28
|
-
* config,
|
|
29
|
-
* db: {},
|
|
30
|
-
* eventBus: defineEventBus({ dbUrl: config.EVENTS_DB_URL, logger }),
|
|
31
|
-
* i18n: await defineI18n({ ... }),
|
|
32
|
-
* logger,
|
|
33
|
-
* mailer: defineMailer({ ... }),
|
|
34
|
-
* server: {
|
|
35
|
-
* port: config.PORT,
|
|
36
|
-
* },
|
|
37
|
-
* worker: {
|
|
38
|
-
* dbUrl: config.WORKER_DB_URL,
|
|
39
|
-
* },
|
|
40
|
-
* });
|
|
41
|
-
* }
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
function defineAppContainer(container) {
|
|
45
|
-
return container;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
//#endregion
|
|
49
|
-
export { defineAppContainer };
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { Logger } from "./logger.mjs";
|
|
2
|
-
import * as drizzle_orm22 from "drizzle-orm";
|
|
3
|
-
import { AnyRelations, EmptyRelations } from "drizzle-orm";
|
|
4
|
-
import { PgTable } from "drizzle-orm/pg-core";
|
|
5
|
-
import * as drizzle_orm_node_postgres0 from "drizzle-orm/node-postgres";
|
|
6
|
-
import * as pg0 from "pg";
|
|
7
|
-
import pg from "pg";
|
|
8
|
-
import { MigrationConfig } from "drizzle-orm/migrator";
|
|
9
|
-
|
|
10
|
-
//#region src/api/database.d.ts
|
|
11
|
-
type PoolConfig = pg.PoolConfig;
|
|
12
|
-
/**
|
|
13
|
-
* Extract qualified table names from db object.
|
|
14
|
-
*/
|
|
15
|
-
type QualifiedTableNames<TDb> = { [K in keyof TDb]: TDb[K] extends {
|
|
16
|
-
_: {
|
|
17
|
-
fullSchema: infer S;
|
|
18
|
-
};
|
|
19
|
-
} ? `${K & string}.${keyof S & string}` : never }[keyof TDb];
|
|
20
|
-
/**
|
|
21
|
-
* The schema used for migrations.
|
|
22
|
-
*/
|
|
23
|
-
declare const migrationsSchema = "public";
|
|
24
|
-
/**
|
|
25
|
-
* The type of migration (schema or data).
|
|
26
|
-
*/
|
|
27
|
-
type MigrationType = "schema" | "data";
|
|
28
|
-
/**
|
|
29
|
-
* Get the migration options for a specific database.
|
|
30
|
-
*
|
|
31
|
-
* @param name Name of the database to get migration options for
|
|
32
|
-
* @param type Type of migration (schema or data), defaults to "schema"
|
|
33
|
-
* @returns Migration configuration for drizzle-orm
|
|
34
|
-
*/
|
|
35
|
-
declare function defineMigrationOpts(name: string, type?: MigrationType): MigrationConfig;
|
|
36
|
-
/**
|
|
37
|
-
* Options for defining the database.
|
|
38
|
-
*/
|
|
39
|
-
interface DefineDatabaseOptions<TSchema extends Record<string, unknown> = Record<string, never>, TRelations extends AnyRelations = EmptyRelations> {
|
|
40
|
-
logger: Logger;
|
|
41
|
-
poolConfig: PoolConfig;
|
|
42
|
-
relations?: TRelations;
|
|
43
|
-
schema?: TSchema;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* The database type.
|
|
47
|
-
*/
|
|
48
|
-
type Database = Awaited<ReturnType<typeof defineDatabase>>;
|
|
49
|
-
/**
|
|
50
|
-
* Generate old and new row JSONB representations for delete/insert/update queries.
|
|
51
|
-
* Uses PostgreSQL 18's OLD/NEW support in RETURNING clause.
|
|
52
|
-
*
|
|
53
|
-
* @param table The table to generate changes for.
|
|
54
|
-
* @returns Object containing `_table`, `old` and `new` JSONB columns.
|
|
55
|
-
*/
|
|
56
|
-
declare function dbChanges<T extends PgTable>(table: T): {
|
|
57
|
-
_table: drizzle_orm22.SQL.Aliased<string>;
|
|
58
|
-
old: drizzle_orm22.SQL.Aliased<({ [Key in keyof T["_"]["columns"] & string]: T["_"]["columns"][Key]["_"]["notNull"] extends true ? T["_"]["columns"][Key]["_"]["data"] : T["_"]["columns"][Key]["_"]["data"] | null } extends infer T_1 ? { [K in keyof T_1]: T_1[K] } : never) | null>;
|
|
59
|
-
new: drizzle_orm22.SQL.Aliased<({ [Key in keyof T["_"]["columns"] & string]: T["_"]["columns"][Key]["_"]["notNull"] extends true ? T["_"]["columns"][Key]["_"]["data"] : T["_"]["columns"][Key]["_"]["data"] | null } extends infer T_2 ? { [K in keyof T_2]: T_2[K] } : never) | null>;
|
|
60
|
-
};
|
|
61
|
-
/**
|
|
62
|
-
* Define the database with the provided options.
|
|
63
|
-
*
|
|
64
|
-
* Algorithm:
|
|
65
|
-
* 1. Create a connection pool with sensible defaults
|
|
66
|
-
* 2. Initialize drizzle ORM with schema and relations
|
|
67
|
-
*
|
|
68
|
-
* @param opts The options for defining the database, including pool configuration, relations, and schema.
|
|
69
|
-
* @template TSchema The schema type for the database.
|
|
70
|
-
* @template TRelations The relations type for the database.
|
|
71
|
-
* @returns The defined database instance.
|
|
72
|
-
*/
|
|
73
|
-
declare function defineDatabase<TSchema extends Record<string, unknown> = Record<string, never>, TRelations extends AnyRelations = EmptyRelations>(opts: DefineDatabaseOptions<TSchema, TRelations>): Promise<drizzle_orm_node_postgres0.NodePgDatabase<TSchema, TRelations> & {
|
|
74
|
-
$client: pg0.Pool;
|
|
75
|
-
}>;
|
|
76
|
-
/**
|
|
77
|
-
* Options for defining a test database.
|
|
78
|
-
*/
|
|
79
|
-
interface DefineTestDatabaseOptions<TSchema extends Record<string, unknown> = Record<string, never>, TRelations extends AnyRelations = EmptyRelations> {
|
|
80
|
-
connectionString: string;
|
|
81
|
-
logger: Logger;
|
|
82
|
-
name: string;
|
|
83
|
-
schema: TSchema;
|
|
84
|
-
relations: TRelations;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Create a single test database with isolated schema.
|
|
88
|
-
*
|
|
89
|
-
* @param connectionString - Database connection string
|
|
90
|
-
* @param name - Name of the test database
|
|
91
|
-
* @returns Test database instance and cleanup function
|
|
92
|
-
*/
|
|
93
|
-
declare function defineTestDatabase<TSchema extends Record<string, unknown> = Record<string, never>, TRelations extends AnyRelations = EmptyRelations>(opts: DefineTestDatabaseOptions<TSchema, TRelations>): Promise<{
|
|
94
|
-
cleanUp: () => Promise<void>;
|
|
95
|
-
db: drizzle_orm_node_postgres0.NodePgDatabase<TSchema, TRelations> & {
|
|
96
|
-
$client: pg0.Pool;
|
|
97
|
-
};
|
|
98
|
-
dbName: string;
|
|
99
|
-
}>;
|
|
100
|
-
//#endregion
|
|
101
|
-
export { Database, DefineDatabaseOptions, DefineTestDatabaseOptions, MigrationType, QualifiedTableNames, dbChanges, defineDatabase, defineMigrationOpts, defineTestDatabase, migrationsSchema };
|