@rvoh/psychic 3.6.0 → 3.7.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.
@@ -132,8 +132,9 @@ ${INDENT} pnpm psy g:sti-child --model-name=House Rental/House extends Rental
132
132
  ${INDENT} pnpm psy g:sti-child --model-name=Condo Rental/Condo extends Rental`, false)
133
133
  .option('--owning-model <modelName>', `The model class that owns this resource. The generated controller will use \`associationQuery\` and \`createAssociation\` on the owning model to scope queries and create records.
134
134
  ${INDENT}
135
- ${INDENT}Defaults to \`this.currentUser\` for non-admin/internal routes (e.g., \`this.currentUser.associationQuery('posts').findOrFail(this.castParam('id', 'uuid'))\`).
136
- ${INDENT}Defaults to \`null\` for admin/internal namespaced controllers (e.g., \`Post.findOrFail(this.castParam('id', 'uuid'))\`).
135
+ ${INDENT}Defaults to \`this.currentUser\` for non-admin routes (e.g., \`this.currentUser.associationQuery('posts').findOrFail(this.castParam('id', 'uuid'))\`).
136
+ ${INDENT}Defaults to \`this.currentInternalUser\` for internal namespaced controllers (e.g., \`this.currentInternalUser.associationQuery('posts').findOrFail(this.castParam('id', 'uuid'))\`).
137
+ ${INDENT}Defaults to \`null\` for admin namespaced controllers (e.g., \`Post.findOrFail(this.castParam('id', 'uuid'))\`).
137
138
  ${INDENT}Supplying an owning-modle changes the the generated code in the controller to be relative to the owning model.
138
139
  ${INDENT}
139
140
  ${INDENT}Example:
@@ -152,7 +153,7 @@ ${INDENT} # model is named GroupDanceLesson instead of LessonDanceGroup`)
152
153
  .option('--no-soft-delete', `skip generating the @SoftDelete() decorator and the corresponding nullable \`deleted_at\` column. By default, generated models use soft-delete semantics (rows are marked deleted via \`deleted_at\` instead of being removed from the database). Pass this flag when you want records to be hard-deleted.`)
153
154
  .argument('<path>', `The URL path for this resource's routes, relative to the root domain. Use \`\\{\\}\` as a placeholder for a parent resource's ID parameter when nesting.
154
155
  ${INDENT}
155
- ${INDENT}The path determines the controller namespace hierarchy. Paths that begin with "admin" and "internal" remove the \`currentUser\` scoping of queries (\`--owning-model\` may be provided to apply query scoping). Each segment maps to a directory level in the controllers folder.
156
+ ${INDENT}The path determines the controller namespace hierarchy. Paths that begin with "internal" scope queries to \`this.currentInternalUser\` instead of \`this.currentUser\`. Paths that begin with "admin" remove owner scoping of queries entirely (\`--owning-model\` may be provided to apply query scoping). Each segment maps to a directory level in the controllers folder.
156
157
  ${INDENT}
157
158
  ${INDENT}Examples:
158
159
  ${INDENT} v1/posts # /v1/posts, /v1/posts/:id
@@ -13,8 +13,10 @@ export default function generateControllerContent({ ancestorName, ancestorImport
13
13
  fullyQualifiedControllerName = DreamApp.system.standardizeFullyQualifiedModelName(fullyQualifiedControllerName);
14
14
  const additionalImports = [];
15
15
  const controllerClassName = DreamApp.system.globalClassNameFromFullyQualifiedModelName(fullyQualifiedControllerName);
16
- // Determine user model variables
17
- const actualOwningModel = owningModel || 'User';
16
+ // Determine user model variables. Internal-namespaced controllers scope to
17
+ // the current internal user the same way default controllers scope to the
18
+ // current user; only the Admin namespace bypasses owner scoping entirely.
19
+ const actualOwningModel = owningModel || (forInternal ? 'InternalUser' : 'User');
18
20
  const owningModelClassName = DreamApp.system.globalClassNameFromFullyQualifiedModelName(actualOwningModel);
19
21
  const owningModelProperty = `current${owningModelClassName}`;
20
22
  let modelClassName;
@@ -34,7 +36,7 @@ export default function generateControllerContent({ ancestorName, ancestorImport
34
36
  ? `
35
37
  serializerKey: 'internal',`
36
38
  : '';
37
- const useDirectModelAccess = (forAdmin || forInternal) && !owningModel;
39
+ const useDirectModelAccess = forAdmin && !owningModel;
38
40
  const loadQueryBase = useDirectModelAccess
39
41
  ? (modelClassName ?? 'no-class-name')
40
42
  : `this.${owningModelProperty}.associationQuery('${pluralizedModelAttributeName}')`;
@@ -31,7 +31,7 @@ function createModelConfiguration(options) {
31
31
  const owningModelVariableName = options.owningModel
32
32
  ? camelize(DreamApp.system.standardizeFullyQualifiedModelName(options.owningModel).split('/').pop())
33
33
  : userVariableName;
34
- const useDirectModelAccess = (options.forAdmin || options.forInternal) && !options.owningModel;
34
+ const useDirectModelAccess = options.forAdmin && !options.owningModel;
35
35
  const simpleCreationCommand = `const ${modelVariableName} = await create${modelClassName}(${useDirectModelAccess ? '' : `{ ${owningModelVariableName} }`})`;
36
36
  return {
37
37
  fullyQualifiedModelName,
@@ -132,8 +132,9 @@ ${INDENT} pnpm psy g:sti-child --model-name=House Rental/House extends Rental
132
132
  ${INDENT} pnpm psy g:sti-child --model-name=Condo Rental/Condo extends Rental`, false)
133
133
  .option('--owning-model <modelName>', `The model class that owns this resource. The generated controller will use \`associationQuery\` and \`createAssociation\` on the owning model to scope queries and create records.
134
134
  ${INDENT}
135
- ${INDENT}Defaults to \`this.currentUser\` for non-admin/internal routes (e.g., \`this.currentUser.associationQuery('posts').findOrFail(this.castParam('id', 'uuid'))\`).
136
- ${INDENT}Defaults to \`null\` for admin/internal namespaced controllers (e.g., \`Post.findOrFail(this.castParam('id', 'uuid'))\`).
135
+ ${INDENT}Defaults to \`this.currentUser\` for non-admin routes (e.g., \`this.currentUser.associationQuery('posts').findOrFail(this.castParam('id', 'uuid'))\`).
136
+ ${INDENT}Defaults to \`this.currentInternalUser\` for internal namespaced controllers (e.g., \`this.currentInternalUser.associationQuery('posts').findOrFail(this.castParam('id', 'uuid'))\`).
137
+ ${INDENT}Defaults to \`null\` for admin namespaced controllers (e.g., \`Post.findOrFail(this.castParam('id', 'uuid'))\`).
137
138
  ${INDENT}Supplying an owning-modle changes the the generated code in the controller to be relative to the owning model.
138
139
  ${INDENT}
139
140
  ${INDENT}Example:
@@ -152,7 +153,7 @@ ${INDENT} # model is named GroupDanceLesson instead of LessonDanceGroup`)
152
153
  .option('--no-soft-delete', `skip generating the @SoftDelete() decorator and the corresponding nullable \`deleted_at\` column. By default, generated models use soft-delete semantics (rows are marked deleted via \`deleted_at\` instead of being removed from the database). Pass this flag when you want records to be hard-deleted.`)
153
154
  .argument('<path>', `The URL path for this resource's routes, relative to the root domain. Use \`\\{\\}\` as a placeholder for a parent resource's ID parameter when nesting.
154
155
  ${INDENT}
155
- ${INDENT}The path determines the controller namespace hierarchy. Paths that begin with "admin" and "internal" remove the \`currentUser\` scoping of queries (\`--owning-model\` may be provided to apply query scoping). Each segment maps to a directory level in the controllers folder.
156
+ ${INDENT}The path determines the controller namespace hierarchy. Paths that begin with "internal" scope queries to \`this.currentInternalUser\` instead of \`this.currentUser\`. Paths that begin with "admin" remove owner scoping of queries entirely (\`--owning-model\` may be provided to apply query scoping). Each segment maps to a directory level in the controllers folder.
156
157
  ${INDENT}
157
158
  ${INDENT}Examples:
158
159
  ${INDENT} v1/posts # /v1/posts, /v1/posts/:id
@@ -13,8 +13,10 @@ export default function generateControllerContent({ ancestorName, ancestorImport
13
13
  fullyQualifiedControllerName = DreamApp.system.standardizeFullyQualifiedModelName(fullyQualifiedControllerName);
14
14
  const additionalImports = [];
15
15
  const controllerClassName = DreamApp.system.globalClassNameFromFullyQualifiedModelName(fullyQualifiedControllerName);
16
- // Determine user model variables
17
- const actualOwningModel = owningModel || 'User';
16
+ // Determine user model variables. Internal-namespaced controllers scope to
17
+ // the current internal user the same way default controllers scope to the
18
+ // current user; only the Admin namespace bypasses owner scoping entirely.
19
+ const actualOwningModel = owningModel || (forInternal ? 'InternalUser' : 'User');
18
20
  const owningModelClassName = DreamApp.system.globalClassNameFromFullyQualifiedModelName(actualOwningModel);
19
21
  const owningModelProperty = `current${owningModelClassName}`;
20
22
  let modelClassName;
@@ -34,7 +36,7 @@ export default function generateControllerContent({ ancestorName, ancestorImport
34
36
  ? `
35
37
  serializerKey: 'internal',`
36
38
  : '';
37
- const useDirectModelAccess = (forAdmin || forInternal) && !owningModel;
39
+ const useDirectModelAccess = forAdmin && !owningModel;
38
40
  const loadQueryBase = useDirectModelAccess
39
41
  ? (modelClassName ?? 'no-class-name')
40
42
  : `this.${owningModelProperty}.associationQuery('${pluralizedModelAttributeName}')`;
@@ -31,7 +31,7 @@ function createModelConfiguration(options) {
31
31
  const owningModelVariableName = options.owningModel
32
32
  ? camelize(DreamApp.system.standardizeFullyQualifiedModelName(options.owningModel).split('/').pop())
33
33
  : userVariableName;
34
- const useDirectModelAccess = (options.forAdmin || options.forInternal) && !options.owningModel;
34
+ const useDirectModelAccess = options.forAdmin && !options.owningModel;
35
35
  const simpleCreationCommand = `const ${modelVariableName} = await create${modelClassName}(${useDirectModelAccess ? '' : `{ ${owningModelVariableName} }`})`;
36
36
  return {
37
37
  fullyQualifiedModelName,
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "type": "module",
3
3
  "name": "@rvoh/psychic",
4
4
  "description": "Typescript web framework",
5
- "version": "3.6.0",
5
+ "version": "3.7.0",
6
6
  "author": "RVOHealth",
7
7
  "repository": {
8
8
  "type": "git",