@aeriajs/builtins 0.0.0 → 0.0.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.
@@ -1,2 +1,122 @@
1
1
  import type { Context } from '@aeriajs/types';
2
- export declare const describe: (context: Context) => Promise<any>;
2
+ import type { Description } from '@aeriajs/types';
3
+ type Payload = {
4
+ collections?: string[];
5
+ noSerialize?: boolean;
6
+ roles?: boolean;
7
+ revalidate?: boolean;
8
+ router?: boolean;
9
+ };
10
+ export declare const describe: (contextOrPayload: Context | Payload) => Promise<import("@aeriajs/types").GenericResponse | import("@aeriajs/types").Left<import("../collections/user/authenticate.js").AuthenticationErrors> | {
11
+ descriptions: Record<string, Description>;
12
+ roles?: string[] | undefined;
13
+ auth?: Partial<{
14
+ user: Pick<import("@aeriajs/types").SchemaWithId<{
15
+ readonly $id: "user";
16
+ readonly required: readonly ["name", "roles", "email"];
17
+ readonly form: readonly ["name", "active", "roles", "email", "phone_number", "picture_file"];
18
+ readonly indexes: readonly ["name"];
19
+ readonly freshItem: {
20
+ readonly active: true;
21
+ };
22
+ readonly properties: {
23
+ readonly name: {
24
+ readonly type: "string";
25
+ };
26
+ readonly given_name: {
27
+ readonly getter: (document: any) => string;
28
+ };
29
+ readonly family_name: {
30
+ readonly getter: (document: any) => string;
31
+ };
32
+ readonly active: {
33
+ readonly type: "boolean";
34
+ };
35
+ readonly roles: {
36
+ readonly type: "array";
37
+ readonly items: {
38
+ readonly type: "string";
39
+ };
40
+ readonly uniqueItems: true;
41
+ };
42
+ readonly email: {
43
+ readonly type: "string";
44
+ readonly inputType: "email";
45
+ readonly unique: true;
46
+ };
47
+ readonly password: {
48
+ readonly type: "string";
49
+ readonly inputType: "password";
50
+ readonly hidden: true;
51
+ };
52
+ readonly phone_number: {
53
+ readonly type: "string";
54
+ readonly mask: "(##) #####-####";
55
+ };
56
+ readonly picture_file: {
57
+ readonly $ref: "file";
58
+ readonly accept: readonly ["image/*"];
59
+ };
60
+ readonly picture: {
61
+ readonly getter: (value: any) => any;
62
+ };
63
+ readonly group: {
64
+ readonly type: "string";
65
+ };
66
+ readonly self_registered: {
67
+ readonly type: "boolean";
68
+ readonly readOnly: true;
69
+ };
70
+ readonly updated_at: {
71
+ readonly type: "string";
72
+ readonly format: "date-time";
73
+ };
74
+ };
75
+ readonly presets: readonly ["crud", "view", "duplicate"];
76
+ readonly layout: {
77
+ readonly name: "grid";
78
+ readonly options: {
79
+ readonly title: "name";
80
+ readonly badge: "roles";
81
+ readonly picture: "picture_file";
82
+ readonly information: "email";
83
+ readonly active: "active";
84
+ readonly translateBadge: true;
85
+ };
86
+ };
87
+ readonly individualActions: {
88
+ readonly 'ui:spawnEdit': {
89
+ readonly name: "Editar";
90
+ readonly icon: "pencil";
91
+ };
92
+ readonly 'route:/dashboard/user/changepass': {
93
+ readonly name: "Mudar senha";
94
+ readonly icon: "key";
95
+ readonly fetchItem: true;
96
+ };
97
+ };
98
+ readonly icon: "users";
99
+ readonly filters: readonly ["name", "roles", "email", "phone_number"];
100
+ readonly table: readonly ["name", "roles", "picture_file", "active", "updated_at"];
101
+ readonly tableMeta: readonly ["email"];
102
+ readonly formLayout: {
103
+ readonly fields: {
104
+ readonly given_name: {
105
+ readonly span: 3;
106
+ };
107
+ readonly family_name: {
108
+ readonly span: 3;
109
+ };
110
+ };
111
+ };
112
+ }>, "name" | "roles" | "email" | "active"> & {
113
+ _id: import("bson").ObjectId | null;
114
+ };
115
+ token: {
116
+ type: "bearer";
117
+ content: string;
118
+ };
119
+ }> | undefined;
120
+ router?: any;
121
+ }>;
122
+ export {};
@@ -6,15 +6,17 @@ const entrypoint_1 = require("@aeriajs/entrypoint");
6
6
  const common_1 = require("@aeriajs/common");
7
7
  const access_control_1 = require("@aeriajs/access-control");
8
8
  const authenticate_js_1 = require("../collections/user/authenticate.js");
9
- const describe = async (context) => {
9
+ const describe = async (contextOrPayload) => {
10
10
  const result = {};
11
- const props = context.request.payload;
11
+ const props = 'request' in contextOrPayload
12
+ ? contextOrPayload.request.payload
13
+ : contextOrPayload;
12
14
  if (props.revalidate) {
13
15
  const authEither = await (0, authenticate_js_1.authenticate)({
14
16
  revalidate: true,
15
17
  }, await (0, api_1.createContext)({
16
18
  collectionName: 'user',
17
- parentContext: context,
19
+ parentContext: contextOrPayload,
18
20
  }));
19
21
  if ((0, common_1.isLeft)(authEither)) {
20
22
  const error = (0, common_1.unwrapEither)(authEither);
@@ -45,10 +47,10 @@ const describe = async (context) => {
45
47
  const router = await (0, entrypoint_1.getRouter)();
46
48
  result.router = router.routesMeta;
47
49
  }
48
- if (props.noSerialize) {
50
+ if (props.noSerialize || !('response' in contextOrPayload)) {
49
51
  return result;
50
52
  }
51
- context.response.setHeader('content-type', 'application/bson');
52
- return context.response.end((0, common_1.serialize)(result));
53
+ contextOrPayload.response.setHeader('content-type', 'application/bson');
54
+ return contextOrPayload.response.end((0, common_1.serialize)(result));
53
55
  };
54
56
  exports.describe = describe;
@@ -174,13 +174,13 @@ import { serialize, isLeft, left, unwrapEither } from "@aeriajs/common";
174
174
  import { getAvailableRoles } from "@aeriajs/access-control";
175
175
  import { authenticate } from "../collections/user/authenticate.mjs";
176
176
  export var describe = function() {
177
- var _ref = _async_to_generator(function(context) {
177
+ var _ref = _async_to_generator(function(contextOrPayload) {
178
178
  var _props_collections, result, props, authEither, _tmp, error, auth, collections, retrievedCollections, descriptions, _tmp1, _tmp2, _i, collectionName, candidate, collection, rawDescription, description, router;
179
179
  return _ts_generator(this, function(_state) {
180
180
  switch(_state.label){
181
181
  case 0:
182
182
  result = {};
183
- props = context.request.payload;
183
+ props = "request" in contextOrPayload ? contextOrPayload.request.payload : contextOrPayload;
184
184
  if (!props.revalidate) return [
185
185
  3,
186
186
  3
@@ -194,7 +194,7 @@ export var describe = function() {
194
194
  4,
195
195
  createContext({
196
196
  collectionName: "user",
197
- parentContext: context
197
+ parentContext: contextOrPayload
198
198
  })
199
199
  ];
200
200
  case 1:
@@ -282,21 +282,21 @@ export var describe = function() {
282
282
  result.router = router.routesMeta;
283
283
  _state.label = 12;
284
284
  case 12:
285
- if (props.noSerialize) {
285
+ if (props.noSerialize || !("response" in contextOrPayload)) {
286
286
  return [
287
287
  2,
288
288
  result
289
289
  ];
290
290
  }
291
- context.response.setHeader("content-type", "application/bson");
291
+ contextOrPayload.response.setHeader("content-type", "application/bson");
292
292
  return [
293
293
  2,
294
- context.response.end(serialize(result))
294
+ contextOrPayload.response.end(serialize(result))
295
295
  ];
296
296
  }
297
297
  });
298
298
  });
299
- return function describe(context) {
299
+ return function describe(contextOrPayload) {
300
300
  return _ref.apply(this, arguments);
301
301
  };
302
302
  }();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/builtins",
3
- "version": "0.0.0",
3
+ "version": "0.0.1",
4
4
  "description": "## Installation",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -40,12 +40,12 @@
40
40
  "mongodb": "^6.1.0"
41
41
  },
42
42
  "peerDependencies": {
43
- "@aeriajs/api": "^0.0.0",
43
+ "@aeriajs/api": "^0.0.1",
44
44
  "@aeriajs/access-control": "^0.0.0",
45
45
  "@aeriajs/entrypoint": "^0.0.0",
46
46
  "@aeriajs/common": "^0.0.0",
47
47
  "@aeriajs/types": "^0.0.0",
48
- "@aeriajs/validation": "^0.0.0"
48
+ "@aeriajs/validation": "^0.0.1"
49
49
  },
50
50
  "scripts": {
51
51
  "test": "echo skipping",