unconventional 1.3.1 → 1.4.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.
@@ -27,7 +27,7 @@ export declare class BaseService<M extends typeof BaseModel> {
27
27
  /**
28
28
  * Gets all instances of the document
29
29
  * @param config - An object containing pagination and sorting options.
30
- * @param config.limit - The maximum number of documents to return.
30
+ * @param config.limit - The maximum number of documents to return. Default 12. Negative limits return all documents.
31
31
  * @param config.cursor - The id of the document to start the query from.
32
32
  * @param config.sort - An object containing the fields to sort by and their sort order.
33
33
  * @param config.filters - A string containing the fields to filter by and their values.
@@ -79,7 +79,7 @@ class BaseService {
79
79
  /**
80
80
  * Gets all instances of the document
81
81
  * @param config - An object containing pagination and sorting options.
82
- * @param config.limit - The maximum number of documents to return.
82
+ * @param config.limit - The maximum number of documents to return. Default 12. Negative limits return all documents.
83
83
  * @param config.cursor - The id of the document to start the query from.
84
84
  * @param config.sort - An object containing the fields to sort by and their sort order.
85
85
  * @param config.filters - A string containing the fields to filter by and their values.
@@ -92,7 +92,7 @@ class BaseService {
92
92
  page = await base_cache_1.BaseCache.getPage(cache, this.model, modifiers);
93
93
  }
94
94
  if (!page) {
95
- const limit = modifiers.limit || 12;
95
+ const limit = modifiers.limit ? (modifiers.limit > 0 ? modifiers.limit : undefined) : 12;
96
96
  page = await this.model.findMany({ limit, ...modifiers });
97
97
  if (cache) {
98
98
  await base_cache_1.BaseCache.setPage(cache, page, modifiers, cacheTTL);
@@ -39,7 +39,7 @@ export interface Relation<Target extends typeof BaseModel = any, Source extends
39
39
  /** The type of relation */
40
40
  type: RelationType;
41
41
  /** The model to relate to */
42
- model: Target;
42
+ model: Target | (() => Target);
43
43
  /** The field on this model to use for the relation */
44
44
  from: keyof InstanceType<Source>;
45
45
  /** The field on the related model to use for the relation */
@@ -19,16 +19,17 @@ function getExpand(model, expand) {
19
19
  const relation = propSummary[parent]?.relation;
20
20
  if (!relation)
21
21
  throw api_error_1.APIError.errInvalidQueryParameter(`Invalid expansion: ${parent}`);
22
+ const relationModel = (relation.model.toString().startsWith('class')) ? relation.model : relation.model();
22
23
  expansions[parent] = {
23
24
  type: [decorator_types_1.RelationType.HasOne, decorator_types_1.RelationType.BelongsTo].includes(relation.type) ? unconventional_pg_queries_1.OneOrMany.One : unconventional_pg_queries_1.OneOrMany.Many,
24
25
  fromTable: model.collection,
25
26
  fromField: relation.from.toString(),
26
- toTable: relation.model.collection,
27
+ toTable: relationModel.collection,
27
28
  toField: relation.to.toString(),
28
29
  throughTable: relation.through?.model.collection,
29
30
  throughFromField: relation.through?.from.toString(),
30
31
  throughToField: relation.through?.to.toString(),
31
- expand: children ? getExpand(relation.model, children) : undefined
32
+ expand: children ? getExpand(relationModel, children) : undefined
32
33
  };
33
34
  });
34
35
  return expansions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unconventional",
3
- "version": "1.3.1",
3
+ "version": "1.4.0",
4
4
  "description": "A complete server built on Cloudflare Workers/Pages",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -38,7 +38,10 @@
38
38
  "docs:dev": "vitepress dev docs",
39
39
  "docs:build": "vitepress build docs",
40
40
  "docs:preview": "vitepress preview docs",
41
- "docs:serve": "vitepress serve docs"
41
+ "docs:serve": "vitepress serve docs",
42
+ "release:major": "changelog -M && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version major && git push origin && git push origin --tags",
43
+ "release:minor": "changelog -m && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version minor && git push origin && git push origin --tags",
44
+ "release:patch": "changelog -p && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version patch && git push origin && git push origin --tags"
42
45
  },
43
46
  "peerDependencies": {
44
47
  "hono": "^4",