meadow 2.0.23 → 2.0.26
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/README.md +110 -141
- package/docs/README.md +34 -230
- package/docs/_cover.md +14 -0
- package/docs/_sidebar.md +44 -12
- package/docs/_topbar.md +5 -0
- package/docs/api/doCount.md +109 -0
- package/docs/api/doCreate.md +132 -0
- package/docs/api/doDelete.md +101 -0
- package/docs/api/doRead.md +122 -0
- package/docs/api/doReads.md +136 -0
- package/docs/api/doUndelete.md +98 -0
- package/docs/api/doUpdate.md +129 -0
- package/docs/api/getRoleName.md +84 -0
- package/docs/api/loadFromPackage.md +153 -0
- package/docs/api/marshalRecordFromSourceToObject.md +92 -0
- package/docs/api/query.md +133 -0
- package/docs/api/rawQueries.md +197 -0
- package/docs/api/reference.md +117 -0
- package/docs/api/setAuthorizer.md +103 -0
- package/docs/api/setDefault.md +90 -0
- package/docs/api/setDefaultIdentifier.md +84 -0
- package/docs/api/setDomain.md +56 -0
- package/docs/api/setIDUser.md +91 -0
- package/docs/api/setJsonSchema.md +92 -0
- package/docs/api/setProvider.md +87 -0
- package/docs/api/setSchema.md +107 -0
- package/docs/api/setScope.md +68 -0
- package/docs/api/validateObject.md +119 -0
- package/docs/architecture.md +316 -0
- package/docs/audit-tracking.md +226 -0
- package/docs/configuration.md +317 -0
- package/docs/providers/meadow-endpoints.md +306 -0
- package/docs/providers/mongodb.md +319 -0
- package/docs/providers/postgresql.md +312 -0
- package/docs/providers/rocksdb.md +297 -0
- package/docs/query-dsl.md +269 -0
- package/docs/quick-start.md +384 -0
- package/docs/raw-queries.md +193 -0
- package/docs/retold-catalog.json +61 -1
- package/docs/retold-keyword-index.json +15860 -4839
- package/docs/soft-deletes.md +224 -0
- package/package.json +36 -9
- package/scripts/bookstore-seed-postgresql.sql +135 -0
- package/scripts/dgraph-test-db.sh +144 -0
- package/scripts/meadow-test-cleanup.sh +5 -1
- package/scripts/mongodb-test-db.sh +98 -0
- package/scripts/postgresql-test-db.sh +124 -0
- package/scripts/solr-test-db.sh +135 -0
- package/source/Meadow.js +5 -0
- package/source/providers/Meadow-Provider-DGraph.js +679 -0
- package/source/providers/Meadow-Provider-MongoDB.js +527 -0
- package/source/providers/Meadow-Provider-PostgreSQL.js +361 -0
- package/source/providers/Meadow-Provider-RocksDB.js +1300 -0
- package/source/providers/Meadow-Provider-Solr.js +726 -0
- package/test/Meadow-Provider-DGraph_tests.js +741 -0
- package/test/Meadow-Provider-MongoDB_tests.js +661 -0
- package/test/Meadow-Provider-PostgreSQL_tests.js +787 -0
- package/test/Meadow-Provider-RocksDB_tests.js +887 -0
- package/test/Meadow-Provider-Solr_tests.js +679 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# rawQueries (Property)
|
|
2
|
+
|
|
3
|
+
Access the raw query manager for overriding auto-generated SQL with custom
|
|
4
|
+
query strings.
|
|
5
|
+
|
|
6
|
+
## Signature
|
|
7
|
+
|
|
8
|
+
```javascript
|
|
9
|
+
var tmpRawQueries = meadow.rawQueries;
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Returns
|
|
13
|
+
|
|
14
|
+
| Type | Description |
|
|
15
|
+
|------|-------------|
|
|
16
|
+
| `Object` | The Meadow-RawQuery manager instance |
|
|
17
|
+
|
|
18
|
+
## Description
|
|
19
|
+
|
|
20
|
+
The `rawQueries` property provides access to a manager that stores and
|
|
21
|
+
retrieves raw query strings. When a raw query override is set for a particular
|
|
22
|
+
operation tag, Meadow passes it to the provider as `queryOverride` instead of
|
|
23
|
+
auto-generating the SQL from the FoxHound query.
|
|
24
|
+
|
|
25
|
+
This is useful when you need hand-tuned SQL for performance, complex joins, or
|
|
26
|
+
database-specific features that the query builder does not support.
|
|
27
|
+
|
|
28
|
+
## Methods
|
|
29
|
+
|
|
30
|
+
### setQuery
|
|
31
|
+
|
|
32
|
+
```javascript
|
|
33
|
+
meadow.rawQueries.setQuery(pQueryTag, pQueryString)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
| Name | Type | Description |
|
|
37
|
+
|------|------|-------------|
|
|
38
|
+
| `pQueryTag` | `string` | The operation tag (e.g. `'Read'`, `'Reads'`, `'Count'`) |
|
|
39
|
+
| `pQueryString` | `string` | The raw SQL query string |
|
|
40
|
+
|
|
41
|
+
**Returns:** The Meadow instance (for chaining off the parent).
|
|
42
|
+
|
|
43
|
+
Sets a raw query override for the given tag. When a CRUD method detects a raw
|
|
44
|
+
query for its tag, it passes the string to the provider.
|
|
45
|
+
|
|
46
|
+
### loadQuery
|
|
47
|
+
|
|
48
|
+
```javascript
|
|
49
|
+
meadow.rawQueries.loadQuery(pQueryTag, pFileName, fCallBack)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
| Name | Type | Description |
|
|
53
|
+
|------|------|-------------|
|
|
54
|
+
| `pQueryTag` | `string` | The operation tag |
|
|
55
|
+
| `pFileName` | `string` | Path to a file containing the SQL query |
|
|
56
|
+
| `fCallBack` | `Function` | Callback: `function(pSuccess)` where `pSuccess` is `true` or `false` |
|
|
57
|
+
|
|
58
|
+
**Returns:** The Meadow instance (for chaining off the parent).
|
|
59
|
+
|
|
60
|
+
Loads a raw query from a file asynchronously using `fs.readFile`. On success,
|
|
61
|
+
the file contents are stored as the raw query for the given tag. On error, the
|
|
62
|
+
query is set to an empty string and `false` is passed to the callback.
|
|
63
|
+
|
|
64
|
+
### getQuery
|
|
65
|
+
|
|
66
|
+
```javascript
|
|
67
|
+
meadow.rawQueries.getQuery(pQueryTag)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
| Name | Type | Description |
|
|
71
|
+
|------|------|-------------|
|
|
72
|
+
| `pQueryTag` | `string` | The operation tag |
|
|
73
|
+
|
|
74
|
+
**Returns:** The raw query string, or `false` if no override is set for that
|
|
75
|
+
tag.
|
|
76
|
+
|
|
77
|
+
### checkQuery
|
|
78
|
+
|
|
79
|
+
```javascript
|
|
80
|
+
meadow.rawQueries.checkQuery(pQueryTag)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
| Name | Type | Description |
|
|
84
|
+
|------|------|-------------|
|
|
85
|
+
| `pQueryTag` | `string` | The operation tag |
|
|
86
|
+
|
|
87
|
+
**Returns:** `true` if a raw query override exists for the tag, `false`
|
|
88
|
+
otherwise.
|
|
89
|
+
|
|
90
|
+
## Supported Override Tags
|
|
91
|
+
|
|
92
|
+
| Tag | Used By | Description |
|
|
93
|
+
|-----|---------|-------------|
|
|
94
|
+
| `'Read'` | `doRead`, `doCreate` (read-back), `doUpdate` (read-back) | Override the single-record read query |
|
|
95
|
+
| `'Reads'` | `doReads` | Override the multi-record read query |
|
|
96
|
+
| `'Delete'` | `doDelete` | Override the delete query |
|
|
97
|
+
| `'Undelete'` | `doUndelete` | Override the undelete query |
|
|
98
|
+
| `'Count'` | `doCount` | Override the count query |
|
|
99
|
+
|
|
100
|
+
**Not supported for override:** `'Create'` and `'Update'` are not currently
|
|
101
|
+
supported. The source notes that these overrides are too complex and the
|
|
102
|
+
feature is deferred.
|
|
103
|
+
|
|
104
|
+
You can also store arbitrary custom query tags for your own use, but only the
|
|
105
|
+
tags listed above are automatically checked by Meadow's CRUD methods.
|
|
106
|
+
|
|
107
|
+
## Examples
|
|
108
|
+
|
|
109
|
+
### Override a read query
|
|
110
|
+
|
|
111
|
+
```javascript
|
|
112
|
+
meadow.rawQueries.setQuery('Read',
|
|
113
|
+
'SELECT b.*, a.Name AS AuthorName ' +
|
|
114
|
+
'FROM Book b ' +
|
|
115
|
+
'JOIN Author a ON b.IDAuthor = a.IDAuthor ' +
|
|
116
|
+
'WHERE b.IDBook = :IDBook AND b.Deleted = 0');
|
|
117
|
+
|
|
118
|
+
var tmpQuery = meadow.query.addFilter('IDBook', 42);
|
|
119
|
+
meadow.doRead(tmpQuery,
|
|
120
|
+
function (pError, pQuery, pRecord)
|
|
121
|
+
{
|
|
122
|
+
// Uses the custom join query instead of auto-generated SQL
|
|
123
|
+
console.log(pRecord);
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Override a reads query with pagination
|
|
128
|
+
|
|
129
|
+
```javascript
|
|
130
|
+
meadow.rawQueries.setQuery('Reads',
|
|
131
|
+
'SELECT b.IDBook, b.Title, COUNT(r.IDReview) AS ReviewCount ' +
|
|
132
|
+
'FROM Book b ' +
|
|
133
|
+
'LEFT JOIN Review r ON b.IDBook = r.IDBook ' +
|
|
134
|
+
'WHERE b.Deleted = 0 ' +
|
|
135
|
+
'GROUP BY b.IDBook, b.Title ' +
|
|
136
|
+
'ORDER BY ReviewCount DESC ' +
|
|
137
|
+
'LIMIT :Cap OFFSET :Begin');
|
|
138
|
+
|
|
139
|
+
var tmpQuery = meadow.query.setCap(10).setBegin(0);
|
|
140
|
+
meadow.doReads(tmpQuery,
|
|
141
|
+
function (pError, pQuery, pRecords)
|
|
142
|
+
{
|
|
143
|
+
console.log(pRecords);
|
|
144
|
+
});
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Load a query from a file
|
|
148
|
+
|
|
149
|
+
```javascript
|
|
150
|
+
meadow.rawQueries.loadQuery('Reads', __dirname + '/queries/BookList.sql',
|
|
151
|
+
function (pSuccess)
|
|
152
|
+
{
|
|
153
|
+
if (!pSuccess)
|
|
154
|
+
{
|
|
155
|
+
console.error('Failed to load query file');
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
var tmpQuery = meadow.query;
|
|
160
|
+
meadow.doReads(tmpQuery,
|
|
161
|
+
function (pError, pQuery, pRecords)
|
|
162
|
+
{
|
|
163
|
+
console.log(pRecords);
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Check before using
|
|
169
|
+
|
|
170
|
+
```javascript
|
|
171
|
+
if (meadow.rawQueries.checkQuery('Count'))
|
|
172
|
+
{
|
|
173
|
+
console.log('Custom count query:', meadow.rawQueries.getQuery('Count'));
|
|
174
|
+
}
|
|
175
|
+
else
|
|
176
|
+
{
|
|
177
|
+
console.log('Using auto-generated count query');
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Notes
|
|
182
|
+
|
|
183
|
+
- Raw queries use FoxHound parameter placeholders (e.g. `:IDBook`, `:Cap`,
|
|
184
|
+
`:Begin`, `:IDUser`). The provider substitutes these with actual values at
|
|
185
|
+
execution time.
|
|
186
|
+
|
|
187
|
+
- The `Read` override is shared between `doRead`, the read-back step of
|
|
188
|
+
`doCreate`, and the read-back step of `doUpdate`. Setting it affects all
|
|
189
|
+
three operations.
|
|
190
|
+
|
|
191
|
+
- When a `loadQuery` file read fails, the query is set to an empty string
|
|
192
|
+
`''` (not `false`). This means FoxHound will receive an empty override
|
|
193
|
+
rather than generating a query. Be aware of this when handling file load
|
|
194
|
+
errors.
|
|
195
|
+
|
|
196
|
+
- Raw query overrides are stored per-instance. Different Meadow instances
|
|
197
|
+
(even for the same scope) maintain independent raw query sets.
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# Meadow API Reference
|
|
2
|
+
|
|
3
|
+
Meadow is a data access layer for the Retold ecosystem. It wraps database
|
|
4
|
+
providers behind a consistent CRUD interface, with schema-driven marshalling,
|
|
5
|
+
audit stamping, and role-based authorization.
|
|
6
|
+
|
|
7
|
+
## Factory
|
|
8
|
+
|
|
9
|
+
```javascript
|
|
10
|
+
var libMeadow = require('meadow');
|
|
11
|
+
var meadow = libMeadow.new(pFable, 'Book');
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
`require('meadow')` returns a constructor object. Call `.new(pFable, pScope)` to
|
|
15
|
+
create an instance bound to a Fable service context and an entity scope.
|
|
16
|
+
|
|
17
|
+
## CRUD Methods
|
|
18
|
+
|
|
19
|
+
| Method | Signature | Description |
|
|
20
|
+
|--------|-----------|-------------|
|
|
21
|
+
| [doCreate](doCreate.md) | `doCreate(pQuery, fCallBack)` | Insert a record, read it back, return marshalled object |
|
|
22
|
+
| [doRead](doRead.md) | `doRead(pQuery, fCallBack)` | Read a single record by filter |
|
|
23
|
+
| [doReads](doReads.md) | `doReads(pQuery, fCallBack)` | Read multiple records with pagination and filtering |
|
|
24
|
+
| [doUpdate](doUpdate.md) | `doUpdate(pQuery, fCallBack)` | Update a record by primary key, read it back |
|
|
25
|
+
| [doDelete](doDelete.md) | `doDelete(pQuery, fCallBack)` | Soft-delete or hard-delete a record |
|
|
26
|
+
| [doUndelete](doUndelete.md) | `doUndelete(pQuery, fCallBack)` | Restore a soft-deleted record |
|
|
27
|
+
| [doCount](doCount.md) | `doCount(pQuery, fCallBack)` | Count records matching filters |
|
|
28
|
+
|
|
29
|
+
All CRUD methods accept a FoxHound query object (obtained from `meadow.query`)
|
|
30
|
+
and a Node-style callback. They return the Meadow instance for chaining.
|
|
31
|
+
|
|
32
|
+
## Configuration Methods
|
|
33
|
+
|
|
34
|
+
All configuration methods are chainable (they return `this`).
|
|
35
|
+
|
|
36
|
+
| Method | Signature | Description |
|
|
37
|
+
|--------|-----------|-------------|
|
|
38
|
+
| [setProvider](setProvider.md) | `setProvider(pProviderName)` | Set the database provider by name |
|
|
39
|
+
| [setScope](setScope.md) | `setScope(pScope)` | Set the entity scope (table name) |
|
|
40
|
+
| [setSchema](setSchema.md) | `setSchema(pSchema)` | Set the column schema array |
|
|
41
|
+
| [setDefaultIdentifier](setDefaultIdentifier.md) | `setDefaultIdentifier(pDefaultIdentifier)` | Set the primary key column name |
|
|
42
|
+
| [setIDUser](setIDUser.md) | `setIDUser(pIDUser)` | Set the user ID for audit stamps |
|
|
43
|
+
| [setJsonSchema](setJsonSchema.md) | `setJsonSchema(pJsonSchema)` | Set JSON Schema for validation |
|
|
44
|
+
| [setDefault](setDefault.md) | `setDefault(pDefault)` | Set the default object template |
|
|
45
|
+
| [setAuthorizer](setAuthorizer.md) | `setAuthorizer(pAuthorizer)` | Set role-based authorization rules |
|
|
46
|
+
| [setDomain](setDomain.md) | `setDomain(pDomain)` | Set the entity domain grouping |
|
|
47
|
+
| [loadFromPackage](loadFromPackage.md) | `loadFromPackage(pPackage)` | Load schema from a JSON file path |
|
|
48
|
+
| [loadFromPackage](loadFromPackage.md) | `loadFromPackageObject(pPackage)` | Load schema from a JS object |
|
|
49
|
+
|
|
50
|
+
## Utility Methods
|
|
51
|
+
|
|
52
|
+
| Method | Signature | Description |
|
|
53
|
+
|--------|-----------|-------------|
|
|
54
|
+
| [validateObject](validateObject.md) | `validateObject(pObject)` | Validate an object against JSON Schema |
|
|
55
|
+
| [marshalRecordFromSourceToObject](marshalRecordFromSourceToObject.md) | `marshalRecordFromSourceToObject(pRecord)` | Convert a database row to a plain object |
|
|
56
|
+
| [getRoleName](getRoleName.md) | `getRoleName(pRoleIndex)` | Get the role name for a numeric index |
|
|
57
|
+
| logSlowQuery | `logSlowQuery(pProfileTime, pQuery)` | Log a warning for slow queries |
|
|
58
|
+
|
|
59
|
+
## Properties
|
|
60
|
+
|
|
61
|
+
All properties are read-only.
|
|
62
|
+
|
|
63
|
+
| Property | Type | Description |
|
|
64
|
+
|----------|------|-------------|
|
|
65
|
+
| `scope` | `string` | The entity scope (table name) |
|
|
66
|
+
| `schema` | `Array` | The column schema array |
|
|
67
|
+
| `schemaFull` | `Object` | The full Meadow-Schema object (includes `validateObject`, `defaultObject`, `authorizer`) |
|
|
68
|
+
| `jsonSchema` | `Object` | The JSON Schema object |
|
|
69
|
+
| `defaultIdentifier` | `string` | The primary key column name (e.g. `'IDBook'`) |
|
|
70
|
+
| `defaultGUIdentifier` | `string` | The GUID column name (e.g. `'GUIDBook'`) |
|
|
71
|
+
| `userIdentifier` | `number` | The current user ID for audit stamps |
|
|
72
|
+
| [query](query.md) | `Object` | A cloned FoxHound query with scope and schema pre-set |
|
|
73
|
+
| [rawQueries](rawQueries.md) | `Object` | The raw query manager for SQL overrides |
|
|
74
|
+
| `provider` | `Object` | The active database provider instance |
|
|
75
|
+
| `providerName` | `string` | The name of the active provider (e.g. `'MySQL'`) |
|
|
76
|
+
|
|
77
|
+
## Fable Services
|
|
78
|
+
|
|
79
|
+
Meadow instances also expose the following properties inherited from the Fable
|
|
80
|
+
service context:
|
|
81
|
+
|
|
82
|
+
| Property | Type | Description |
|
|
83
|
+
|----------|------|-------------|
|
|
84
|
+
| `fable` | `Object` | The parent Fable instance |
|
|
85
|
+
| `settings` | `Object` | The Fable settings object |
|
|
86
|
+
| `log` | `Object` | The Fable logger |
|
|
87
|
+
|
|
88
|
+
## Quick Start
|
|
89
|
+
|
|
90
|
+
```javascript
|
|
91
|
+
var libFable = require('fable');
|
|
92
|
+
var libMeadow = require('meadow');
|
|
93
|
+
|
|
94
|
+
var tmpFable = libFable.new({ MeadowProvider: 'MySQL' });
|
|
95
|
+
var tmpMeadow = libMeadow.new(tmpFable, 'Book')
|
|
96
|
+
.setSchema([
|
|
97
|
+
{ Column: 'IDBook', Type: 'AutoIdentity' },
|
|
98
|
+
{ Column: 'GUIDBook', Type: 'AutoGUID' },
|
|
99
|
+
{ Column: 'Title', Type: 'String', Size: '128' },
|
|
100
|
+
{ Column: 'Created', Type: 'CreateDate' },
|
|
101
|
+
{ Column: 'CreatingIDUser', Type: 'CreateIDUser' },
|
|
102
|
+
{ Column: 'Modified', Type: 'UpdateDate' },
|
|
103
|
+
{ Column: 'ModifyingIDUser', Type: 'UpdateIDUser' },
|
|
104
|
+
{ Column: 'Deleted', Type: 'Deleted' },
|
|
105
|
+
{ Column: 'DeletingIDUser', Type: 'DeleteIDUser' },
|
|
106
|
+
{ Column: 'DeleteDate', Type: 'DeleteDate' }
|
|
107
|
+
])
|
|
108
|
+
.setIDUser(1);
|
|
109
|
+
|
|
110
|
+
// Create a record
|
|
111
|
+
var tmpQuery = tmpMeadow.query.addRecord({ Title: 'The Hobbit' });
|
|
112
|
+
tmpMeadow.doCreate(tmpQuery,
|
|
113
|
+
function (pError, pCreateQuery, pReadQuery, pRecord)
|
|
114
|
+
{
|
|
115
|
+
console.log('Created:', pRecord);
|
|
116
|
+
});
|
|
117
|
+
```
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# setAuthorizer
|
|
2
|
+
|
|
3
|
+
Set the role-based authorization rules for this Meadow instance.
|
|
4
|
+
|
|
5
|
+
## Signature
|
|
6
|
+
|
|
7
|
+
```javascript
|
|
8
|
+
meadow.setAuthorizer(pAuthorizer)
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Parameters
|
|
12
|
+
|
|
13
|
+
| Name | Type | Description |
|
|
14
|
+
|------|------|-------------|
|
|
15
|
+
| `pAuthorizer` | `Object` | An object mapping role names to operation permissions |
|
|
16
|
+
|
|
17
|
+
## Returns
|
|
18
|
+
|
|
19
|
+
Returns the Meadow instance for chaining.
|
|
20
|
+
|
|
21
|
+
## Description
|
|
22
|
+
|
|
23
|
+
`setAuthorizer` sets the authorization rules used by Meadow-Endpoints to
|
|
24
|
+
enforce role-based access control on CRUD operations. Each key in the object is
|
|
25
|
+
a role name, and each value is an object mapping operations to permission
|
|
26
|
+
strings.
|
|
27
|
+
|
|
28
|
+
The authorizer is stored on the schema object and is accessible via
|
|
29
|
+
`meadow.schemaFull.authorizer`.
|
|
30
|
+
|
|
31
|
+
## Authorizer Structure
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
34
|
+
{
|
|
35
|
+
"Role Name": {
|
|
36
|
+
"Create": "Allow" | "Deny" | <custom>,
|
|
37
|
+
"Read": "Allow" | "Deny" | <custom>,
|
|
38
|
+
"Reads": "Allow" | "Deny" | <custom>,
|
|
39
|
+
"Update": "Allow" | "Deny" | <custom>,
|
|
40
|
+
"Delete": "Allow" | "Deny" | <custom>,
|
|
41
|
+
"Undelete": "Allow" | "Deny" | <custom>,
|
|
42
|
+
"Count": "Allow" | "Deny" | <custom>
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Examples
|
|
48
|
+
|
|
49
|
+
### Basic role configuration
|
|
50
|
+
|
|
51
|
+
```javascript
|
|
52
|
+
meadow.setAuthorizer({
|
|
53
|
+
"Unauthenticated": {
|
|
54
|
+
"Create": "Deny",
|
|
55
|
+
"Read": "Allow",
|
|
56
|
+
"Reads": "Allow",
|
|
57
|
+
"Update": "Deny",
|
|
58
|
+
"Delete": "Deny",
|
|
59
|
+
"Undelete": "Deny",
|
|
60
|
+
"Count": "Allow"
|
|
61
|
+
},
|
|
62
|
+
"User": {
|
|
63
|
+
"Create": "Allow",
|
|
64
|
+
"Read": "Allow",
|
|
65
|
+
"Reads": "Allow",
|
|
66
|
+
"Update": "Allow",
|
|
67
|
+
"Delete": "Allow",
|
|
68
|
+
"Undelete": "Deny",
|
|
69
|
+
"Count": "Allow"
|
|
70
|
+
},
|
|
71
|
+
"Administrator": {
|
|
72
|
+
"Create": "Allow",
|
|
73
|
+
"Read": "Allow",
|
|
74
|
+
"Reads": "Allow",
|
|
75
|
+
"Update": "Allow",
|
|
76
|
+
"Delete": "Allow",
|
|
77
|
+
"Undelete": "Allow",
|
|
78
|
+
"Count": "Allow"
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Access after setting
|
|
84
|
+
|
|
85
|
+
```javascript
|
|
86
|
+
console.log(meadow.schemaFull.authorizer);
|
|
87
|
+
// { "Unauthenticated": { ... }, "User": { ... }, ... }
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Notes
|
|
91
|
+
|
|
92
|
+
- If `pAuthorizer` is not an object, it falls back to an empty object `{}`.
|
|
93
|
+
|
|
94
|
+
- The authorizer is primarily consumed by Meadow-Endpoints, which checks
|
|
95
|
+
permissions before executing CRUD operations on HTTP routes. Meadow itself
|
|
96
|
+
does not enforce authorization during direct `doCreate`, `doRead`, etc. calls.
|
|
97
|
+
|
|
98
|
+
- Role names should match the names returned by `getRoleName()`. The default
|
|
99
|
+
role names are: `'Unauthenticated'`, `'User'`, `'Manager'`, `'Director'`,
|
|
100
|
+
`'Executive'`, `'Administrator'`.
|
|
101
|
+
|
|
102
|
+
- When loading from a package file or object, the `Authorization` property of
|
|
103
|
+
the package is passed to `setAuthorizer` automatically.
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# setDefault
|
|
2
|
+
|
|
3
|
+
Set the default object template used when creating and marshalling records.
|
|
4
|
+
|
|
5
|
+
## Signature
|
|
6
|
+
|
|
7
|
+
```javascript
|
|
8
|
+
meadow.setDefault(pDefault)
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Parameters
|
|
12
|
+
|
|
13
|
+
| Name | Type | Description |
|
|
14
|
+
|------|------|-------------|
|
|
15
|
+
| `pDefault` | `Object` | A plain object with default values for all columns |
|
|
16
|
+
|
|
17
|
+
## Returns
|
|
18
|
+
|
|
19
|
+
Returns the Meadow instance for chaining.
|
|
20
|
+
|
|
21
|
+
## Description
|
|
22
|
+
|
|
23
|
+
`setDefault` sets the template object that is used in two places:
|
|
24
|
+
|
|
25
|
+
1. **During `doCreate`** -- The default object is merged with the submitted
|
|
26
|
+
record before insertion, ensuring that all schema columns have values even if
|
|
27
|
+
the caller omitted them.
|
|
28
|
+
|
|
29
|
+
2. **During marshalling** -- When `marshalRecordFromSourceToObject` converts a
|
|
30
|
+
database row to a plain object, it starts with a copy of the default object
|
|
31
|
+
and overlays the provider-marshalled values.
|
|
32
|
+
|
|
33
|
+
This ensures consistent object shapes throughout the application, regardless of
|
|
34
|
+
whether the database returned null columns or the caller submitted a partial
|
|
35
|
+
record.
|
|
36
|
+
|
|
37
|
+
## Examples
|
|
38
|
+
|
|
39
|
+
### Set default values
|
|
40
|
+
|
|
41
|
+
```javascript
|
|
42
|
+
meadow.setDefault({
|
|
43
|
+
IDBook: 0,
|
|
44
|
+
GUIDBook: '',
|
|
45
|
+
Title: '',
|
|
46
|
+
Author: 'Unknown',
|
|
47
|
+
PageCount: 0,
|
|
48
|
+
Created: '',
|
|
49
|
+
CreatingIDUser: 0,
|
|
50
|
+
Modified: '',
|
|
51
|
+
ModifyingIDUser: 0,
|
|
52
|
+
Deleted: 0,
|
|
53
|
+
DeletingIDUser: 0,
|
|
54
|
+
DeleteDate: ''
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Effect on create
|
|
59
|
+
|
|
60
|
+
```javascript
|
|
61
|
+
meadow.setDefault({ Title: 'Untitled', Author: 'Unknown', PageCount: 0 });
|
|
62
|
+
|
|
63
|
+
var tmpQuery = meadow.query
|
|
64
|
+
.addRecord({ Title: 'Dune' });
|
|
65
|
+
|
|
66
|
+
meadow.doCreate(tmpQuery,
|
|
67
|
+
function (pError, pCreateQuery, pReadQuery, pRecord)
|
|
68
|
+
{
|
|
69
|
+
// pRecord.Author will be 'Unknown' (from defaults)
|
|
70
|
+
// pRecord.Title will be 'Dune' (from submitted record)
|
|
71
|
+
// pRecord.PageCount will be 0 (from defaults)
|
|
72
|
+
console.log(pRecord);
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Access via schemaFull
|
|
77
|
+
|
|
78
|
+
```javascript
|
|
79
|
+
console.log(meadow.schemaFull.defaultObject);
|
|
80
|
+
// { IDBook: 0, GUIDBook: '', Title: '', ... }
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Notes
|
|
84
|
+
|
|
85
|
+
- If `pDefault` is not an object, it falls back to an empty object `{}`.
|
|
86
|
+
|
|
87
|
+
- The default object is accessible through `meadow.schemaFull.defaultObject`.
|
|
88
|
+
|
|
89
|
+
- When loading from a package file or object, the `DefaultObject` property
|
|
90
|
+
of the package is passed to `setDefault` automatically.
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# setDefaultIdentifier
|
|
2
|
+
|
|
3
|
+
Set the primary key column name for this Meadow instance.
|
|
4
|
+
|
|
5
|
+
## Signature
|
|
6
|
+
|
|
7
|
+
```javascript
|
|
8
|
+
meadow.setDefaultIdentifier(pDefaultIdentifier)
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Parameters
|
|
12
|
+
|
|
13
|
+
| Name | Type | Description |
|
|
14
|
+
|------|------|-------------|
|
|
15
|
+
| `pDefaultIdentifier` | `string` | The primary key column name (e.g. `'IDBook'`) |
|
|
16
|
+
|
|
17
|
+
## Returns
|
|
18
|
+
|
|
19
|
+
Returns the Meadow instance for chaining.
|
|
20
|
+
|
|
21
|
+
## Description
|
|
22
|
+
|
|
23
|
+
`setDefaultIdentifier` sets the primary key column name used for automated
|
|
24
|
+
queries. It also derives the GUID identifier by prepending `'GU'` to the value.
|
|
25
|
+
For example, setting the identifier to `'IDBook'` automatically sets the GUID
|
|
26
|
+
identifier to `'GUIDBook'`.
|
|
27
|
+
|
|
28
|
+
After setting the identifier, `updateProviderState()` is called to synchronize
|
|
29
|
+
with the active provider.
|
|
30
|
+
|
|
31
|
+
By default, the identifier is derived from the scope at construction time:
|
|
32
|
+
`'ID' + scope` (e.g., scope `'Book'` produces identifier `'IDBook'`).
|
|
33
|
+
|
|
34
|
+
## Examples
|
|
35
|
+
|
|
36
|
+
### Default behavior
|
|
37
|
+
|
|
38
|
+
```javascript
|
|
39
|
+
var meadow = libMeadow.new(tmpFable, 'Book');
|
|
40
|
+
console.log(meadow.defaultIdentifier); // 'IDBook'
|
|
41
|
+
console.log(meadow.defaultGUIdentifier); // 'GUIDBook'
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Custom identifier
|
|
45
|
+
|
|
46
|
+
```javascript
|
|
47
|
+
var meadow = libMeadow.new(tmpFable, 'Book')
|
|
48
|
+
.setDefaultIdentifier('BookID');
|
|
49
|
+
|
|
50
|
+
console.log(meadow.defaultIdentifier); // 'BookID'
|
|
51
|
+
console.log(meadow.defaultGUIdentifier); // 'GUBookID'
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Use with non-standard naming
|
|
55
|
+
|
|
56
|
+
```javascript
|
|
57
|
+
var meadow = libMeadow.new(tmpFable, 'UserProfile')
|
|
58
|
+
.setDefaultIdentifier('ProfileID');
|
|
59
|
+
|
|
60
|
+
// doUpdate will require records to have a 'ProfileID' property
|
|
61
|
+
var tmpQuery = meadow.query
|
|
62
|
+
.addRecord({ ProfileID: 5, DisplayName: 'Alice' });
|
|
63
|
+
|
|
64
|
+
meadow.doUpdate(tmpQuery,
|
|
65
|
+
function (pError, pUpdateQuery, pReadQuery, pRecord)
|
|
66
|
+
{
|
|
67
|
+
console.log(pRecord);
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Notes
|
|
72
|
+
|
|
73
|
+
- The GUID identifier is always `'GU' + pDefaultIdentifier`. This is a fixed
|
|
74
|
+
convention and cannot be set independently.
|
|
75
|
+
|
|
76
|
+
- The default identifier is used by `doUpdate` to determine which column
|
|
77
|
+
identifies the record to update. If the record does not contain this column,
|
|
78
|
+
the update is aborted.
|
|
79
|
+
|
|
80
|
+
- The default identifier is also used by `doCreate` to read back the newly
|
|
81
|
+
created record after insertion.
|
|
82
|
+
|
|
83
|
+
- Changing the default identifier calls `updateProviderState()` to synchronize
|
|
84
|
+
with the active provider.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# setDomain
|
|
2
|
+
|
|
3
|
+
Set the entity domain for organizational grouping.
|
|
4
|
+
|
|
5
|
+
## Signature
|
|
6
|
+
|
|
7
|
+
```javascript
|
|
8
|
+
meadow.setDomain(pDomain)
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Parameters
|
|
12
|
+
|
|
13
|
+
| Name | Type | Description |
|
|
14
|
+
|------|------|-------------|
|
|
15
|
+
| `pDomain` | `string` | The domain name for this entity |
|
|
16
|
+
|
|
17
|
+
## Returns
|
|
18
|
+
|
|
19
|
+
Returns the Meadow instance for chaining.
|
|
20
|
+
|
|
21
|
+
## Description
|
|
22
|
+
|
|
23
|
+
`setDomain` sets an organizational grouping label for the Meadow instance.
|
|
24
|
+
Domains allow multiple entities to be grouped logically, which is useful in
|
|
25
|
+
multi-tenant or modular applications.
|
|
26
|
+
|
|
27
|
+
The default domain is `'Default'`.
|
|
28
|
+
|
|
29
|
+
## Examples
|
|
30
|
+
|
|
31
|
+
### Set a custom domain
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
34
|
+
var meadow = libMeadow.new(tmpFable, 'Book')
|
|
35
|
+
.setDomain('Library');
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Set domain from a package
|
|
39
|
+
|
|
40
|
+
```javascript
|
|
41
|
+
// In a package JSON file:
|
|
42
|
+
// { "Scope": "Book", "Domain": "Library", ... }
|
|
43
|
+
|
|
44
|
+
var meadow = libMeadow.new(tmpFable)
|
|
45
|
+
.loadFromPackage('./Book.json');
|
|
46
|
+
// Domain is set to 'Library' from the package
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Notes
|
|
50
|
+
|
|
51
|
+
- The domain is a free-form string with no restrictions on content.
|
|
52
|
+
|
|
53
|
+
- The default value is `'Default'` if not explicitly set.
|
|
54
|
+
|
|
55
|
+
- When loading from a package file or object, the `Domain` property of the
|
|
56
|
+
package is passed to `setDomain` automatically.
|