@lucashw68/nsdb 1.0.0-rc.2

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.
Files changed (49) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/GET_STARTED.md +709 -0
  3. package/LICENSE +21 -0
  4. package/README.md +159 -0
  5. package/cli/index.js +83 -0
  6. package/helpers/args.js +22 -0
  7. package/helpers/config.js +142 -0
  8. package/helpers/generated.js +48 -0
  9. package/helpers/io.js +39 -0
  10. package/helpers/metadata.js +19 -0
  11. package/helpers/names.js +16 -0
  12. package/helpers/relations.js +101 -0
  13. package/helpers/shell.js +15 -0
  14. package/helpers/tables.js +79 -0
  15. package/helpers/ts.js +37 -0
  16. package/module.ts +151 -0
  17. package/nsdb.config.example.mjs +39 -0
  18. package/nsdb.config.example.ts +42 -0
  19. package/package.json +114 -0
  20. package/runtime/components/Form/NsdbRelationSelect.vue +258 -0
  21. package/runtime/components/NsdbForm.vue +865 -0
  22. package/runtime/components/NsdbList.vue +961 -0
  23. package/runtime/composables/useNsdbProfile.ts +119 -0
  24. package/runtime/composables/useNsdbSchemas.ts +176 -0
  25. package/runtime/composables/useSupabaseApi.ts +177 -0
  26. package/runtime/composables/useSupabaseApiStorage.ts +337 -0
  27. package/runtime/composables/useSupabaseModels.ts +412 -0
  28. package/runtime/query.ts +126 -0
  29. package/runtime/stores/createDbStore.ts +439 -0
  30. package/runtime/stores/createSingletonDbStore.ts +67 -0
  31. package/runtime/utils/dataFreshness.ts +47 -0
  32. package/runtime/utils/storage.ts +41 -0
  33. package/scripts/clear.js +64 -0
  34. package/scripts/generate-composables.js +100 -0
  35. package/scripts/generate-enums.js +106 -0
  36. package/scripts/generate-metadata.js +165 -0
  37. package/scripts/generate-models.js +164 -0
  38. package/scripts/generate-schemas.js +443 -0
  39. package/scripts/generate-stores.js +90 -0
  40. package/scripts/generate-types.js +196 -0
  41. package/scripts/init.js +225 -0
  42. package/templates/model.template.ts +48 -0
  43. package/templates/schema.template.ts +13 -0
  44. package/templates/useNsdbModel.template.ts +9 -0
  45. package/types/config.ts +50 -0
  46. package/types/entities.ts +66 -0
  47. package/types/index.ts +14 -0
  48. package/types/list.ts +78 -0
  49. package/types/model.ts +57 -0
package/types/list.ts ADDED
@@ -0,0 +1,78 @@
1
+ export type Column = {
2
+ key: string
3
+ label: string
4
+ format?: (value: unknown, row: Record<string, unknown>) => string
5
+ }
6
+
7
+ export type NsdbTableClasses = {
8
+ wrapper: string
9
+ headerWrapper: string
10
+ headerTitle: string
11
+ headerSubtitle: string
12
+ toolbar: string
13
+ searchInput: string
14
+ error: string
15
+ tableContainer: string
16
+ table: string
17
+ thead: string
18
+ theadRow: string
19
+ th: string
20
+ actionsTh: string
21
+ loadingCell: string
22
+ emptyCell: string
23
+ bodyRow: string
24
+ td: string
25
+ actionsTd: string
26
+ deleteButton: string
27
+ footer: string
28
+ pagination: string
29
+ pageButton: string
30
+ pageButtonActive: string
31
+ pageButtonDisabled: string
32
+ }
33
+
34
+ /** #########################################################
35
+ * Filter & Sorting
36
+ * ##########################################################
37
+ */
38
+
39
+ export type OrderDirection = 'asc' | 'desc'
40
+
41
+ export type SortState = {
42
+ key: string | null
43
+ direction: OrderDirection | null
44
+ }
45
+
46
+ export interface ListOptions {
47
+ select?: string
48
+ where?: WhereClause
49
+ orderBy?: string
50
+ orderDirection?: OrderDirection
51
+
52
+ /**
53
+ * Tri relationnel : ex orderBy='title', orderForeignTable='book'
54
+ * => order=book(title).asc (embedded order)
55
+ */
56
+ orderForeignTable?: string
57
+
58
+ limit?: number
59
+ offset?: number
60
+
61
+ /**
62
+ * Recherche texte simple (ilike) via OR sur plusieurs colonnes.
63
+ * Exemple:
64
+ * search: 'clover'
65
+ * searchColumns: ['title', 'author', 'book.title']
66
+ */
67
+ search?: string
68
+ searchColumns?: readonly string[]
69
+ }
70
+
71
+ export interface WhereOperator {
72
+ op: 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'ilike' | 'in'
73
+ value: unknown
74
+ }
75
+
76
+ export type WherePrimitive = string | number | boolean | null
77
+ export type WhereValue = WherePrimitive | WherePrimitive[] | WhereOperator | WhereOperator[]
78
+ export type WhereClause = Record<string, WhereValue>
package/types/model.ts ADDED
@@ -0,0 +1,57 @@
1
+ import type { Ref } from 'vue'
2
+ import type { OrderDirection, WhereClause } from './list'
3
+
4
+ // Keep operators extensible like PostgREST. Generated models type search/order
5
+ // columns, while runtime exposure validation protects automatic UI paths.
6
+ export type ModelWhere<_Column extends string = string> = WhereClause
7
+
8
+ /** Canonical query object accepted by generated table models. */
9
+ export interface ModelQuery<
10
+ Include extends string = string,
11
+ Column extends string = string,
12
+ > {
13
+ /** Raw PostgREST select escape hatch. Prefer `include` for generated relations. */
14
+ select?: string
15
+ where?: ModelWhere<Column>
16
+ orderBy?: Column | `${string}.${string}` | Partial<Record<Column | `${string}.${string}`, OrderDirection>>
17
+ orderDirection?: OrderDirection
18
+ orderForeignTable?: string
19
+ limit?: number
20
+ offset?: number
21
+ search?: string
22
+ searchColumns?: readonly Column[]
23
+ include?: readonly Include[]
24
+ /** Advanced store option: explicitly merge rows instead of replacing the current collection. */
25
+ merge?: boolean
26
+ /** Advanced store option overriding the configured TTL for this request. */
27
+ staleTimeMs?: number
28
+ }
29
+
30
+ /** A mutation may target either the generated primary-key value or a row of the same model. */
31
+ export type ModelMutationTarget<
32
+ TRow,
33
+ TPrimaryKey extends Extract<keyof TRow, string>,
34
+ > = Extract<TRow[TPrimaryKey], string | number> | TRow
35
+
36
+ /** Stable public state and operations exposed by a table model. */
37
+ export interface ModelHandle<
38
+ TRow,
39
+ TInsert,
40
+ TUpdate,
41
+ TPrimaryKey extends Extract<keyof TRow, string> = Extract<keyof TRow, string>,
42
+ > {
43
+ items: Ref<TRow[]>
44
+ totalCount: Ref<number | null>
45
+ loading: Ref<boolean>
46
+ error: Ref<unknown>
47
+ stale: Ref<boolean>
48
+ getById(id: string | number, select?: string): Promise<TRow | null>
49
+ create(payload: TInsert): Promise<TRow>
50
+ update(target: ModelMutationTarget<TRow, TPrimaryKey>, payload: TUpdate): Promise<TRow | null>
51
+ remove(target: ModelMutationTarget<TRow, TPrimaryKey>): Promise<void>
52
+ fetch(query?: ModelQuery<string, Extract<keyof TRow, string>>): Promise<TRow[]>
53
+ refresh(query?: ModelQuery<string, Extract<keyof TRow, string>>): Promise<TRow[]>
54
+ invalidate(): void
55
+ subscribe(): void
56
+ unsubscribe(): void | Promise<void>
57
+ }