@gencow/core 0.1.25 → 0.1.27
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/crud.d.ts +12 -0
- package/dist/crud.js +16 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/package.json +7 -9
- package/src/__tests__/helpers/seed-like-fill.ts +3 -3
- package/src/crud.ts +33 -0
- package/src/index.ts +2 -1
package/dist/crud.d.ts
CHANGED
|
@@ -74,6 +74,18 @@ type CrudOptions<T extends PgTable> = {
|
|
|
74
74
|
*/
|
|
75
75
|
methods?: ("list" | "get" | "create" | "update" | "remove")[];
|
|
76
76
|
};
|
|
77
|
+
export interface CrudCodegenMeta {
|
|
78
|
+
tableName: string;
|
|
79
|
+
prefix: string;
|
|
80
|
+
methods: ("list" | "get" | "create" | "update" | "remove")[];
|
|
81
|
+
allowedFilters: string[];
|
|
82
|
+
searchFields: string[];
|
|
83
|
+
isPublic: boolean;
|
|
84
|
+
}
|
|
85
|
+
declare global {
|
|
86
|
+
var __gencow_crudCodegenRegistry: Map<string, CrudCodegenMeta>;
|
|
87
|
+
}
|
|
88
|
+
export declare function getRegisteredCrudCodegenMeta(): CrudCodegenMeta[];
|
|
77
89
|
/** 지원 연산자 목록 */
|
|
78
90
|
declare const FILTER_OPS: readonly ["eq", "ne", "gt", "gte", "lt", "lte", "in", "nin", "like", "ilike"];
|
|
79
91
|
type FilterOp = (typeof FILTER_OPS)[number];
|
package/dist/crud.js
CHANGED
|
@@ -46,6 +46,13 @@ const _ownerRlsTables = [];
|
|
|
46
46
|
export function getOwnerRlsTables() {
|
|
47
47
|
return _ownerRlsTables;
|
|
48
48
|
}
|
|
49
|
+
if (!globalThis.__gencow_crudCodegenRegistry) {
|
|
50
|
+
globalThis.__gencow_crudCodegenRegistry = new Map();
|
|
51
|
+
}
|
|
52
|
+
const crudCodegenRegistry = globalThis.__gencow_crudCodegenRegistry;
|
|
53
|
+
export function getRegisteredCrudCodegenMeta() {
|
|
54
|
+
return Array.from(crudCodegenRegistry.values());
|
|
55
|
+
}
|
|
49
56
|
// ─── Helpers ────────────────────────────────────────────
|
|
50
57
|
/**
|
|
51
58
|
* id 컬럼의 Drizzle dataType을 검사하여 적절한 validator를 반환.
|
|
@@ -353,6 +360,15 @@ export function crud(table, options) {
|
|
|
353
360
|
// ── methods 필터링: 지정된 메서드만 레지스트리 등록 ──
|
|
354
361
|
// methods 옵션 미지정 시 전체 5개 등록 (하위호환)
|
|
355
362
|
const enabledMethods = new Set(options?.methods ?? ["list", "get", "create", "update", "remove"]);
|
|
363
|
+
const enabledMethodsList = Array.from(enabledMethods);
|
|
364
|
+
crudCodegenRegistry.set(prefix, {
|
|
365
|
+
tableName,
|
|
366
|
+
prefix,
|
|
367
|
+
methods: enabledMethodsList,
|
|
368
|
+
allowedFilters: (options?.allowedFilters ?? []).map((field) => String(field)),
|
|
369
|
+
searchFields: (options?.searchFields ?? []).map((field) => String(field)),
|
|
370
|
+
isPublic,
|
|
371
|
+
});
|
|
356
372
|
// ── list ──────────────────────────────────────
|
|
357
373
|
const listDef = !enabledMethods.has("list")
|
|
358
374
|
? undefined
|
package/dist/index.d.ts
CHANGED
|
@@ -25,5 +25,6 @@ export { ownerRls, getOwnerRlsMeta, registerOwnerRls } from "./rls.js";
|
|
|
25
25
|
export type { OwnerRlsMeta } from "./rls.js";
|
|
26
26
|
export { createRlsDb } from "./rls-db.js";
|
|
27
27
|
export type { RlsSessionContext } from "./rls-db.js";
|
|
28
|
-
export { crud, parseFilterNode, applyFilterOp, getOwnerRlsTables } from "./crud.js";
|
|
28
|
+
export { crud, parseFilterNode, applyFilterOp, getOwnerRlsTables, getRegisteredCrudCodegenMeta } from "./crud.js";
|
|
29
|
+
export type { CrudCodegenMeta } from "./crud.js";
|
|
29
30
|
export { crud as gencowCrud } from "./crud.js";
|
package/dist/index.js
CHANGED
|
@@ -16,6 +16,6 @@ export { defineAuth } from "./auth-config.js";
|
|
|
16
16
|
// ─── RLS + CRUD Factory ───────────
|
|
17
17
|
export { ownerRls, getOwnerRlsMeta, registerOwnerRls } from "./rls.js";
|
|
18
18
|
export { createRlsDb } from "./rls-db.js";
|
|
19
|
-
export { crud, parseFilterNode, applyFilterOp, getOwnerRlsTables } from "./crud.js";
|
|
19
|
+
export { crud, parseFilterNode, applyFilterOp, getOwnerRlsTables, getRegisteredCrudCodegenMeta } from "./crud.js";
|
|
20
20
|
// Deprecated alias — 하위호환용, 향후 메이저 버전에서 제거 예정
|
|
21
21
|
export { crud as gencowCrud } from "./crud.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gencow/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.27",
|
|
4
4
|
"description": "Gencow core library — defineQuery, defineMutation, reactive subscriptions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -21,13 +21,6 @@
|
|
|
21
21
|
"dist/",
|
|
22
22
|
"src/"
|
|
23
23
|
],
|
|
24
|
-
"scripts": {
|
|
25
|
-
"db:generate:fixture-basic": "drizzle-kit generate --config ./src/__tests__/fixtures/basic/drizzle.config.ts",
|
|
26
|
-
"build": "tsc",
|
|
27
|
-
"typecheck": "tsc --noEmit",
|
|
28
|
-
"prepublishOnly": "npm run build",
|
|
29
|
-
"postinstall": "tsc"
|
|
30
|
-
},
|
|
31
24
|
"dependencies": {
|
|
32
25
|
"node-cron": "^4.2.1"
|
|
33
26
|
},
|
|
@@ -46,5 +39,10 @@
|
|
|
46
39
|
"hono": "^4.12.0",
|
|
47
40
|
"typescript": "^5.9.3",
|
|
48
41
|
"uuid": "^13.0.0"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"db:generate:fixture-basic": "drizzle-kit generate --config ./src/__tests__/fixtures/basic/drizzle.config.ts",
|
|
45
|
+
"build": "tsc",
|
|
46
|
+
"typecheck": "tsc --noEmit"
|
|
49
47
|
}
|
|
50
|
-
}
|
|
48
|
+
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* the same generators as `seed()` without listing every column in test fixtures.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { getTableColumns, getTableName } from "drizzle-orm";
|
|
8
8
|
import type { InferInsertModel } from "drizzle-orm";
|
|
9
9
|
import type { PgColumn, PgTable } from "drizzle-orm/pg-core";
|
|
10
10
|
import { getTableConfig } from "drizzle-orm/pg-core";
|
|
@@ -90,7 +90,7 @@ function getAllBaseColumns(baseColumn: PgColumn): NonNullable<SeedColumn["baseCo
|
|
|
90
90
|
* Drizzle `PgTable` → drizzle-seed `Table` (same shape as `getPostgresInfo` in drizzle-seed).
|
|
91
91
|
*/
|
|
92
92
|
export function drizzlePgTableToSeedTable(pgTable: PgTable, schemaKey: string): SeedTable {
|
|
93
|
-
const colsMap =
|
|
93
|
+
const colsMap = getTableColumns(pgTable) as Record<string, PgColumn>;
|
|
94
94
|
const tableConfig = getTableConfig(pgTable);
|
|
95
95
|
const columns: SeedColumn[] = Object.entries(colsMap).map(([tsName, column]) => {
|
|
96
96
|
const c = pgColumnForSeed(column);
|
|
@@ -133,7 +133,7 @@ export function fillPartialRowsForInsert<T extends PgTable>(
|
|
|
133
133
|
const schemaKey = options?.schemaKey ?? getTableName(pgTable);
|
|
134
134
|
const seedService = new SeedService();
|
|
135
135
|
const seedTable = drizzlePgTableToSeedTable(pgTable, schemaKey);
|
|
136
|
-
const colsMap =
|
|
136
|
+
const colsMap = getTableColumns(pgTable) as Record<string, PgColumn>;
|
|
137
137
|
const tsNames = Object.keys(colsMap);
|
|
138
138
|
const baseSeed = options?.seed ?? 0;
|
|
139
139
|
const count = partialRows.length;
|
package/src/crud.ts
CHANGED
|
@@ -108,6 +108,29 @@ type CrudOptions<T extends PgTable> = {
|
|
|
108
108
|
methods?: ("list" | "get" | "create" | "update" | "remove")[];
|
|
109
109
|
};
|
|
110
110
|
|
|
111
|
+
export interface CrudCodegenMeta {
|
|
112
|
+
tableName: string;
|
|
113
|
+
prefix: string;
|
|
114
|
+
methods: ("list" | "get" | "create" | "update" | "remove")[];
|
|
115
|
+
allowedFilters: string[];
|
|
116
|
+
searchFields: string[];
|
|
117
|
+
isPublic: boolean;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
declare global {
|
|
121
|
+
var __gencow_crudCodegenRegistry: Map<string, CrudCodegenMeta>;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (!globalThis.__gencow_crudCodegenRegistry) {
|
|
125
|
+
globalThis.__gencow_crudCodegenRegistry = new Map();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const crudCodegenRegistry = globalThis.__gencow_crudCodegenRegistry;
|
|
129
|
+
|
|
130
|
+
export function getRegisteredCrudCodegenMeta(): CrudCodegenMeta[] {
|
|
131
|
+
return Array.from(crudCodegenRegistry.values());
|
|
132
|
+
}
|
|
133
|
+
|
|
111
134
|
// ─── Helpers ────────────────────────────────────────────
|
|
112
135
|
|
|
113
136
|
/**
|
|
@@ -472,6 +495,16 @@ export function crud<T extends PgTable>(table: T, options?: CrudOptions<T>) {
|
|
|
472
495
|
// ── methods 필터링: 지정된 메서드만 레지스트리 등록 ──
|
|
473
496
|
// methods 옵션 미지정 시 전체 5개 등록 (하위호환)
|
|
474
497
|
const enabledMethods = new Set(options?.methods ?? ["list", "get", "create", "update", "remove"]);
|
|
498
|
+
const enabledMethodsList = Array.from(enabledMethods) as CrudCodegenMeta["methods"];
|
|
499
|
+
|
|
500
|
+
crudCodegenRegistry.set(prefix, {
|
|
501
|
+
tableName,
|
|
502
|
+
prefix,
|
|
503
|
+
methods: enabledMethodsList,
|
|
504
|
+
allowedFilters: (options?.allowedFilters ?? []).map((field) => String(field)),
|
|
505
|
+
searchFields: (options?.searchFields ?? []).map((field) => String(field)),
|
|
506
|
+
isPublic,
|
|
507
|
+
});
|
|
475
508
|
|
|
476
509
|
// ── list ──────────────────────────────────────
|
|
477
510
|
|
package/src/index.ts
CHANGED
|
@@ -92,7 +92,8 @@ export { ownerRls, getOwnerRlsMeta, registerOwnerRls } from "./rls.js";
|
|
|
92
92
|
export type { OwnerRlsMeta } from "./rls.js";
|
|
93
93
|
export { createRlsDb } from "./rls-db.js";
|
|
94
94
|
export type { RlsSessionContext } from "./rls-db.js";
|
|
95
|
-
export { crud, parseFilterNode, applyFilterOp, getOwnerRlsTables } from "./crud.js";
|
|
95
|
+
export { crud, parseFilterNode, applyFilterOp, getOwnerRlsTables, getRegisteredCrudCodegenMeta } from "./crud.js";
|
|
96
|
+
export type { CrudCodegenMeta } from "./crud.js";
|
|
96
97
|
|
|
97
98
|
// Deprecated alias — 하위호환용, 향후 메이저 버전에서 제거 예정
|
|
98
99
|
export { crud as gencowCrud } from "./crud.js";
|