@deessejs/collections 0.0.51 → 0.1.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.
Files changed (120) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +204 -0
  3. package/dist/index.js +868 -22
  4. package/dist/index.js.map +1 -0
  5. package/dist/index.mjs +821 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/package.json +66 -72
  8. package/dist/collections/define.d.ts +0 -43
  9. package/dist/collections/define.js +0 -13
  10. package/dist/collections/extend-fields.d.ts +0 -3
  11. package/dist/collections/extend-fields.js +0 -13
  12. package/dist/collections/index.d.ts +0 -1
  13. package/dist/collections/index.js +0 -17
  14. package/dist/collections/types.d.ts +0 -29
  15. package/dist/collections/types.js +0 -2
  16. package/dist/config/index.d.ts +0 -2
  17. package/dist/config/index.js +0 -45
  18. package/dist/config/orchestrator.d.ts +0 -8
  19. package/dist/config/orchestrator.js +0 -70
  20. package/dist/config/types.d.ts +0 -14
  21. package/dist/config/types.js +0 -2
  22. package/dist/database/types.d.ts +0 -10
  23. package/dist/database/types.js +0 -2
  24. package/dist/drizzle/generate.d.ts +0 -2
  25. package/dist/drizzle/generate.js +0 -49
  26. package/dist/drizzle/index.d.ts +0 -31
  27. package/dist/drizzle/index.js +0 -24
  28. package/dist/drizzle/types.js +0 -1
  29. package/dist/dsl/collections.d.ts +0 -13
  30. package/dist/dsl/collections.js +0 -14
  31. package/dist/dsl/index.d.ts +0 -1
  32. package/dist/dsl/index.js +0 -17
  33. package/dist/dsl/types.d.ts +0 -1
  34. package/dist/dsl/types.js +0 -2
  35. package/dist/esm/collections/define.d.ts +0 -43
  36. package/dist/esm/collections/define.js +0 -9
  37. package/dist/esm/collections/extend-fields.d.ts +0 -3
  38. package/dist/esm/collections/extend-fields.js +0 -9
  39. package/dist/esm/collections/index.d.ts +0 -1
  40. package/dist/esm/collections/index.js +0 -1
  41. package/dist/esm/collections/types.d.ts +0 -29
  42. package/dist/esm/collections/types.js +0 -1
  43. package/dist/esm/config/index.d.ts +0 -5
  44. package/dist/esm/config/index.js +0 -13
  45. package/dist/esm/config/orchestrator.d.ts +0 -8
  46. package/dist/esm/config/orchestrator.js +0 -66
  47. package/dist/esm/config/types.d.ts +0 -14
  48. package/dist/esm/config/types.js +0 -1
  49. package/dist/esm/database/types.d.ts +0 -10
  50. package/dist/esm/database/types.js +0 -1
  51. package/dist/esm/drizzle/generate.d.ts +0 -2
  52. package/dist/esm/drizzle/generate.js +0 -30
  53. package/dist/esm/drizzle/index.d.ts +0 -31
  54. package/dist/esm/drizzle/index.js +0 -20
  55. package/dist/esm/drizzle/types.d.ts +0 -0
  56. package/dist/esm/drizzle/types.js +0 -1
  57. package/dist/esm/dsl/collections.d.ts +0 -13
  58. package/dist/esm/dsl/collections.js +0 -10
  59. package/dist/esm/dsl/index.d.ts +0 -1
  60. package/dist/esm/dsl/index.js +0 -1
  61. package/dist/esm/fields/constraints.d.ts +0 -6
  62. package/dist/esm/fields/constraints.js +0 -59
  63. package/dist/esm/fields/core.d.ts +0 -71
  64. package/dist/esm/fields/core.js +0 -27
  65. package/dist/esm/fields/field.d.ts +0 -24
  66. package/dist/esm/fields/field.js +0 -33
  67. package/dist/esm/fields/index.d.ts +0 -4
  68. package/dist/esm/fields/index.js +0 -4
  69. package/dist/esm/fields/types.d.ts +0 -48
  70. package/dist/esm/fields/types.js +0 -1
  71. package/dist/esm/index.d.ts +0 -8
  72. package/dist/esm/index.js +0 -8
  73. package/dist/esm/next/index.d.ts +0 -5
  74. package/dist/esm/next/index.js +0 -17
  75. package/dist/esm/plugins/index.d.ts +0 -2
  76. package/dist/esm/plugins/index.js +0 -3
  77. package/dist/esm/plugins/types.d.ts +0 -1
  78. package/dist/esm/plugins/types.js +0 -1
  79. package/dist/esm/providers/index.d.ts +0 -2
  80. package/dist/esm/providers/index.js +0 -53
  81. package/dist/esm/providers/types.d.ts +0 -8
  82. package/dist/esm/providers/types.js +0 -1
  83. package/dist/esm/utils/deep-partial.d.ts +0 -3
  84. package/dist/esm/utils/deep-partial.js +0 -1
  85. package/dist/esm/utils/exact.d.ts +0 -1
  86. package/dist/esm/utils/exact.js +0 -1
  87. package/dist/esm/utils/union-intersection.d.ts +0 -1
  88. package/dist/esm/utils/union-intersection.js +0 -1
  89. package/dist/esm/worker/index.d.ts +0 -2
  90. package/dist/esm/worker/index.js +0 -32
  91. package/dist/fields/constraints.d.ts +0 -6
  92. package/dist/fields/constraints.js +0 -67
  93. package/dist/fields/core.d.ts +0 -71
  94. package/dist/fields/core.js +0 -33
  95. package/dist/fields/field.d.ts +0 -24
  96. package/dist/fields/field.js +0 -38
  97. package/dist/fields/index.d.ts +0 -4
  98. package/dist/fields/index.js +0 -20
  99. package/dist/fields/types.d.ts +0 -48
  100. package/dist/fields/types.js +0 -2
  101. package/dist/index.d.ts +0 -8
  102. package/dist/next/index.d.ts +0 -5
  103. package/dist/next/index.js +0 -55
  104. package/dist/plugins/index.d.ts +0 -2
  105. package/dist/plugins/index.js +0 -7
  106. package/dist/plugins/types.d.ts +0 -1
  107. package/dist/plugins/types.js +0 -2
  108. package/dist/providers/index.d.ts +0 -2
  109. package/dist/providers/index.js +0 -57
  110. package/dist/providers/types.d.ts +0 -8
  111. package/dist/providers/types.js +0 -2
  112. package/dist/utils/deep-partial.d.ts +0 -3
  113. package/dist/utils/deep-partial.js +0 -2
  114. package/dist/utils/exact.d.ts +0 -1
  115. package/dist/utils/exact.js +0 -1
  116. package/dist/utils/union-intersection.d.ts +0 -1
  117. package/dist/utils/union-intersection.js +0 -2
  118. package/dist/worker/index.d.ts +0 -1
  119. package/dist/worker/index.js +0 -101
  120. /package/{dist/drizzle/types.d.ts → public/.gitkeep} +0 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Nesalia Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -0,0 +1,204 @@
1
+ <p align="center">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="public/icon.png">
4
+ <source media="(prefers-color-scheme: light)" srcset="public/icon.png">
5
+ <img src="public/icon.png" alt="collections" width="150" height="150" style="border-radius: 50%;">
6
+ </picture>
7
+ </p>
8
+
9
+ <h1 align="center">@deessejs/collections</h1>
10
+
11
+ <p align="center">
12
+ <a href="https://www.npmjs.com/package/@deessejs/collections">
13
+ <img src="https://img.shields.io/npm/v/@deessejs/collections" alt="npm Version">
14
+ </a>
15
+ <a href="https://www.npmjs.com/package/@deessejs/collections">
16
+ <img src="https://img.shields.io/bundlejs/size/@deessejs/collections" alt="Bundle Size">
17
+ </a>
18
+ <a href="https://github.com/nesalia-inc/collections/actions">
19
+ <img src="https://img.shields.io/github/actions/workflow/status/nesalia-inc/collections/test?label=tests" alt="Tests">
20
+ </a>
21
+ <a href="https://github.com/nesalia-inc/collections/actions">
22
+ <img src="https://img.shields.io/badge/coverage-100%25-brightgreen" alt="Coverage">
23
+ </a>
24
+ <a href="https://github.com/nesalia-inc/collections/blob/main/LICENSE">
25
+ <img src="https://img.shields.io/github/license/nesalia-inc/collections" alt="License">
26
+ </a>
27
+ </p>
28
+
29
+ > High-level abstraction layer built on top of Drizzle ORM.
30
+
31
+ ## Requirements
32
+
33
+ - TypeScript 5.0+
34
+ - Drizzle ORM
35
+
36
+ ## Installation
37
+
38
+ ```bash
39
+ # Install collections
40
+ npm install @deessejs/collections
41
+
42
+ # Or using pnpm
43
+ pnpm add @deessejs/collections
44
+
45
+ # Or using yarn
46
+ yarn add @deessejs/collections
47
+ ```
48
+
49
+ ## Quick Start
50
+
51
+ ```typescript
52
+ import { collection, field, f } from '@deessejs/collections'
53
+
54
+ // Define a collection
55
+ const users = collection({
56
+ slug: 'users',
57
+ fields: {
58
+ name: field({ fieldType: f.text() }),
59
+ email: field({ fieldType: f.text() })
60
+ }
61
+ })
62
+ ```
63
+
64
+ ## Features
65
+
66
+ - **Collection API** - Define database collections with a clean API
67
+ - **Hooks System** - Lifecycle hooks for all CRUD operations
68
+ - **Type Safety** - Full TypeScript support with inferred types
69
+ - **Drizzle Integration** - Built on top of Drizzle ORM
70
+
71
+ ## Hooks
72
+
73
+ Execute custom logic at each stage of database operations:
74
+
75
+ ```typescript
76
+ const users = collection({
77
+ slug: 'users',
78
+ fields: {
79
+ name: field({ fieldType: f.text() }),
80
+ email: field({ fieldType: f.text() })
81
+ },
82
+ hooks: {
83
+ beforeCreate: [async (context) => {
84
+ // Validate or transform data before creating
85
+ context.data.email = context.data.email.toLowerCase()
86
+ }],
87
+ afterCreate: [async (context) => {
88
+ // Handle post-creation logic
89
+ console.log(`Created user: ${context.result.id}`)
90
+ }]
91
+ }
92
+ })
93
+ ```
94
+
95
+ ### Available Hooks
96
+
97
+ | Hook | Description |
98
+ |------|-------------|
99
+ | `beforeOperation` | Runs before any operation |
100
+ | `afterOperation` | Runs after any operation |
101
+ | `beforeCreate` | Runs before create operation |
102
+ | `afterCreate` | Runs after create operation |
103
+ | `beforeUpdate` | Runs before update operation |
104
+ | `afterUpdate` | Runs after update operation |
105
+ | `beforeDelete` | Runs before delete operation |
106
+ | `afterDelete` | Runs after delete operation |
107
+ | `beforeRead` | Runs before read operation |
108
+ | `afterRead` | Runs after read operation |
109
+
110
+ ## Field Types
111
+
112
+ ```typescript
113
+ import { f } from '@deessejs/collections'
114
+
115
+ // Text field
116
+ field({ fieldType: f.text() })
117
+
118
+ // Number field
119
+ field({ fieldType: f.number() })
120
+
121
+ // Boolean field
122
+ field({ fieldType: f.boolean() })
123
+
124
+ // UUID field
125
+ field({ fieldType: f.uuid() })
126
+
127
+ // Timestamp field
128
+ field({ fieldType: f.timestamp() })
129
+ ```
130
+
131
+ ## API Reference
132
+
133
+ ### collection()
134
+
135
+ Create a new collection definition.
136
+
137
+ ```typescript
138
+ const users = collection({
139
+ slug: 'users',
140
+ name: 'Users',
141
+ fields: {
142
+ name: field({ fieldType: f.text() })
143
+ },
144
+ hooks: {
145
+ beforeCreate: [async (ctx) => { /* ... */ }]
146
+ }
147
+ })
148
+ ```
149
+
150
+ ### field()
151
+
152
+ Define a field in a collection.
153
+
154
+ ```typescript
155
+ const name = field({
156
+ fieldType: f.text(),
157
+ optional: false,
158
+ default: 'default value'
159
+ })
160
+ ```
161
+
162
+ ### createCollectionOperations()
163
+
164
+ Create CRUD operations for a collection.
165
+
166
+ ```typescript
167
+ import { createCollectionOperations } from '@deessejs/collections'
168
+
169
+ const operations = createCollectionOperations(
170
+ collection,
171
+ tableName,
172
+ db,
173
+ table,
174
+ hooks
175
+ )
176
+
177
+ // Create
178
+ await operations.create({ data: { name: 'John' } })
179
+
180
+ // Read
181
+ await operations.findMany()
182
+
183
+ // Update
184
+ await operations.update({ where: { id: 1 }, data: { name: 'Jane' } })
185
+
186
+ // Delete
187
+ await operations.delete({ where: { id: 1 } })
188
+ ```
189
+
190
+ ## Contributing
191
+
192
+ Contributions are welcome! Please feel free to submit a Pull Request.
193
+
194
+ ## Author
195
+
196
+ - **Nesalia Inc.**
197
+
198
+ ## Security
199
+
200
+ If you discover any security vulnerabilities, please send an e-mail to security@nesalia.com.
201
+
202
+ ## License
203
+
204
+ MIT License - see the [LICENSE](LICENSE) file for details.