@porulle/core 0.10.0 → 0.10.1

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.
@@ -10,6 +10,14 @@ export interface DatabaseAdapter<TDatabase = unknown, TTransaction = unknown> {
10
10
  provider: string;
11
11
  db: TDatabase;
12
12
  transaction<T>(fn: (tx: TTransaction) => Promise<T>): Promise<T>;
13
+ /**
14
+ * Zero-migration adapters (e.g. PGlite) set this so the runtime pushes any
15
+ * plugin-declared tables (`config.customSchemas`) at boot. Plugin schemas
16
+ * only exist after plugins run in `defineConfig` — i.e. after this adapter was
17
+ * constructed — so the adapter cannot create them itself. Omit/false when the
18
+ * consumer manages migrations (e.g. production Postgres via drizzle-kit).
19
+ */
20
+ autoMigrate?: boolean;
13
21
  }
14
22
  export interface DatabaseConnectionFactoryInput {
15
23
  adapter: DatabaseAdapter;
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/kernel/database/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,WAAW,eAAe,CAAC,SAAS,GAAG,OAAO,EAAE,YAAY,GAAG,OAAO;IAC1E,QAAQ,EAAE,MAAM,CAAC;IACjB,EAAE,EAAE,SAAS,CAAC;IACd,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,YAAY,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CAClE;AAED,MAAM,WAAW,8BAA8B;IAC7C,OAAO,EAAE,eAAe,CAAC;CAC1B;AASD;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,CAMpC;AAsCD,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,8BAA8B,GAAG,eAAe,CAS/F"}
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/kernel/database/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,WAAW,eAAe,CAAC,SAAS,GAAG,OAAO,EAAE,YAAY,GAAG,OAAO;IAC1E,QAAQ,EAAE,MAAM,CAAC;IACjB,EAAE,EAAE,SAAS,CAAC;IACd,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,YAAY,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACjE;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,8BAA8B;IAC7C,OAAO,EAAE,eAAe,CAAC;CAC1B;AASD;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,CAMpC;AAsCD,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,8BAA8B,GAAG,eAAe,CAS/F"}
@@ -54,5 +54,5 @@ export declare function getSchemaFiles(): string[];
54
54
  * Drizzle instance bound to your database. `drizzle-kit` must be available
55
55
  * (it is the standard schema tool); a clear error is thrown if it is not.
56
56
  */
57
- export declare function pushSchema(drizzleInstance: unknown): Promise<void>;
57
+ export declare function pushSchema(drizzleInstance: unknown, config?: CommerceConfig): Promise<void>;
58
58
  //# sourceMappingURL=migrate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../../src/kernel/database/migrate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAEtC;;;GAGG;AACH,wBAAgB,SAAS,kBAExB;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,MAAM,CAAC,EAAE,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAwB5E;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,MAAM,EAAE,CASxC;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,IAAI,MAAM,EAAE,CAKzC;AAED;;;;;;;;GAQG;AACH,wBAAsB,UAAU,CAAC,eAAe,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAkBxE"}
1
+ {"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../../src/kernel/database/migrate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAEtC;;;GAGG;AACH,wBAAgB,SAAS,kBAExB;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,MAAM,CAAC,EAAE,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAwB5E;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,MAAM,EAAE,CASxC;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,IAAI,MAAM,EAAE,CAKzC;AAED;;;;;;;;GAQG;AACH,wBAAsB,UAAU,CAC9B,eAAe,EAAE,OAAO,EACxB,MAAM,CAAC,EAAE,cAAc,GACtB,OAAO,CAAC,IAAI,CAAC,CAqBf"}
@@ -86,7 +86,7 @@ export function getSchemaFiles() {
86
86
  * Drizzle instance bound to your database. `drizzle-kit` must be available
87
87
  * (it is the standard schema tool); a clear error is thrown if it is not.
88
88
  */
89
- export async function pushSchema(drizzleInstance) {
89
+ export async function pushSchema(drizzleInstance, config) {
90
90
  const require = createRequire(import.meta.url);
91
91
  let drizzleKit;
92
92
  try {
@@ -95,7 +95,10 @@ export async function pushSchema(drizzleInstance) {
95
95
  catch {
96
96
  throw new Error("pushSchema() requires `drizzle-kit` to be installed. Add it to your project: bun add -d drizzle-kit");
97
97
  }
98
+ // With a config, push the merged core + plugin schema so plugin-declared
99
+ // tables are created too; without one, push core only (backward compatible).
100
+ const schemaToApply = config ? buildSchema(config) : getSchema();
98
101
  // drizzle-kit needs the native driver result shape; unwrap a normalized db.
99
- const { apply } = await drizzleKit.pushSchema(getSchema(), unwrapDb(drizzleInstance));
102
+ const { apply } = await drizzleKit.pushSchema(schemaToApply, unwrapDb(drizzleInstance));
100
103
  await apply();
101
104
  }
@@ -1 +1 @@
1
- {"version":3,"file":"commerce.d.ts","sourceRoot":"","sources":["../../src/runtime/commerce.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAI1C,OAAO,EAAc,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAkB,KAAK,gBAAgB,EAAwB,MAAM,wBAAwB,CAAC;AAErG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,MAAM,WAAW,gBAAgB;IAC/B,0EAA0E;IAC1E,GAAG,EAAE,gBAAgB,CAAC;IAEtB,8DAA8D;IAC9D,MAAM,EAAE,MAAM,CAAC;IAEf,mDAAmD;IACnD,EAAE,EAAE,OAAO,CAAC;IAEZ,yDAAyD;IACzD,IAAI,EAAE,YAAY,CAAC;IAEnB,aAAa;IACb,MAAM,EAAE,MAAM,CAAC;IAEf;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,gBAAgB,CAAC;IAE1C;;;;;;;;;;OAUG;IACH,eAAe,CAAC,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,GAAG,gBAAgB,CAAC;CACtE;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC,gBAAgB,CAAC,CAoC3B"}
1
+ {"version":3,"file":"commerce.d.ts","sourceRoot":"","sources":["../../src/runtime/commerce.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAK1C,OAAO,EAAc,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAkB,KAAK,gBAAgB,EAAwB,MAAM,wBAAwB,CAAC;AAErG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,MAAM,WAAW,gBAAgB;IAC/B,0EAA0E;IAC1E,GAAG,EAAE,gBAAgB,CAAC;IAEtB,8DAA8D;IAC9D,MAAM,EAAE,MAAM,CAAC;IAEf,mDAAmD;IACnD,EAAE,EAAE,OAAO,CAAC;IAEZ,yDAAyD;IACzD,IAAI,EAAE,YAAY,CAAC;IAEnB,aAAa;IACb,MAAM,EAAE,MAAM,CAAC;IAEf;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,gBAAgB,CAAC;IAE1C;;;;;;;;;;OAUG;IACH,eAAe,CAAC,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,GAAG,gBAAgB,CAAC;CACtE;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC,gBAAgB,CAAC,CA6C3B"}
@@ -1,4 +1,5 @@
1
1
  import { createKernel } from "./kernel.js";
2
+ import { pushSchema } from "../kernel/database/migrate.js";
2
3
  import { ensureDefaultOrg, setBootDefaultOrgId } from "../auth/org.js";
3
4
  import { setBootStrictOrgResolution } from "../auth/strict-org-resolution.js";
4
5
  import { createAuth } from "../auth/setup.js";
@@ -17,6 +18,14 @@ import { createLocalAPI } from "../kernel/local-api.js";
17
18
  */
18
19
  export async function createCommerce(config) {
19
20
  const kernel = createKernel(config);
21
+ // Zero-migration adapters (PGlite) push core schema at construction, but a
22
+ // plugin's own tables live in `config.customSchemas`, which only exist after
23
+ // plugins run in `defineConfig` — i.e. after the adapter was constructed.
24
+ // Create them now so plugin routes have their tables. Guarded on both signals
25
+ // so plugin-less stores and migration-managed adapters (Postgres) are untouched.
26
+ if (config.databaseAdapter?.autoMigrate && config.customSchemas?.length) {
27
+ await pushSchema(kernel.database.db, config);
28
+ }
20
29
  setBootStrictOrgResolution(config.auth?.strictOrgResolution === true);
21
30
  // Register the config-driven org ID so resolveOrgId() can use it
22
31
  // without requiring every service to have config access.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@porulle/core",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -56,8 +56,8 @@
56
56
  "eslint": "^9.39.1",
57
57
  "typescript": "5.9.2",
58
58
  "vitest": "^3.2.4",
59
- "@porulle/typescript-config": "0.1.0",
60
- "@porulle/eslint-config": "0.1.0"
59
+ "@porulle/eslint-config": "0.1.0",
60
+ "@porulle/typescript-config": "0.1.0"
61
61
  },
62
62
  "publishConfig": {
63
63
  "access": "public"
@@ -10,6 +10,14 @@ export interface DatabaseAdapter<TDatabase = unknown, TTransaction = unknown> {
10
10
  provider: string;
11
11
  db: TDatabase;
12
12
  transaction<T>(fn: (tx: TTransaction) => Promise<T>): Promise<T>;
13
+ /**
14
+ * Zero-migration adapters (e.g. PGlite) set this so the runtime pushes any
15
+ * plugin-declared tables (`config.customSchemas`) at boot. Plugin schemas
16
+ * only exist after plugins run in `defineConfig` — i.e. after this adapter was
17
+ * constructed — so the adapter cannot create them itself. Omit/false when the
18
+ * consumer manages migrations (e.g. production Postgres via drizzle-kit).
19
+ */
20
+ autoMigrate?: boolean;
13
21
  }
14
22
 
15
23
  export interface DatabaseConnectionFactoryInput {
@@ -103,7 +103,10 @@ export function getSchemaFiles(): string[] {
103
103
  * Drizzle instance bound to your database. `drizzle-kit` must be available
104
104
  * (it is the standard schema tool); a clear error is thrown if it is not.
105
105
  */
106
- export async function pushSchema(drizzleInstance: unknown): Promise<void> {
106
+ export async function pushSchema(
107
+ drizzleInstance: unknown,
108
+ config?: CommerceConfig,
109
+ ): Promise<void> {
107
110
  const require = createRequire(import.meta.url);
108
111
  let drizzleKit: {
109
112
  pushSchema(
@@ -118,7 +121,10 @@ export async function pushSchema(drizzleInstance: unknown): Promise<void> {
118
121
  "pushSchema() requires `drizzle-kit` to be installed. Add it to your project: bun add -d drizzle-kit",
119
122
  );
120
123
  }
124
+ // With a config, push the merged core + plugin schema so plugin-declared
125
+ // tables are created too; without one, push core only (backward compatible).
126
+ const schemaToApply = config ? buildSchema(config) : getSchema();
121
127
  // drizzle-kit needs the native driver result shape; unwrap a normalized db.
122
- const { apply } = await drizzleKit.pushSchema(getSchema(), unwrapDb(drizzleInstance));
128
+ const { apply } = await drizzleKit.pushSchema(schemaToApply, unwrapDb(drizzleInstance));
123
129
  await apply();
124
130
  }
@@ -2,6 +2,7 @@ import type { Actor } from "../auth/types.js";
2
2
  import type { CommerceConfig } from "../config/types.js";
3
3
  import type { Kernel } from "./kernel.js";
4
4
  import { createKernel } from "./kernel.js";
5
+ import { pushSchema } from "../kernel/database/migrate.js";
5
6
  import { ensureDefaultOrg, setBootDefaultOrgId } from "../auth/org.js";
6
7
  import { setBootStrictOrgResolution } from "../auth/strict-org-resolution.js";
7
8
  import { createAuth, type AuthInstance } from "../auth/setup.js";
@@ -122,6 +123,15 @@ export async function createCommerce(
122
123
  ): Promise<CommerceInstance> {
123
124
  const kernel = createKernel(config);
124
125
 
126
+ // Zero-migration adapters (PGlite) push core schema at construction, but a
127
+ // plugin's own tables live in `config.customSchemas`, which only exist after
128
+ // plugins run in `defineConfig` — i.e. after the adapter was constructed.
129
+ // Create them now so plugin routes have their tables. Guarded on both signals
130
+ // so plugin-less stores and migration-managed adapters (Postgres) are untouched.
131
+ if (config.databaseAdapter?.autoMigrate && config.customSchemas?.length) {
132
+ await pushSchema(kernel.database.db, config);
133
+ }
134
+
125
135
  setBootStrictOrgResolution(config.auth?.strictOrgResolution === true);
126
136
 
127
137
  // Register the config-driven org ID so resolveOrgId() can use it