Skip to content

Commit 1f9d879

Browse files
author
Lee Richmond
committed
Add afterSync hook
This is called with a diff of changes between the ID map and model instance. Helpful for things like "highlight the 'name' cell when the 'name' attribute is updated". Enhances fetch middleware specs while here.
1 parent 960473f commit 1f9d879

35 files changed

+207
-91
lines changed

lib-esm/associations.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib-esm/associations.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib-esm/model.d.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,19 @@ import { MiddlewareStack, BeforeFilter, AfterFilter } from "./middleware-stack";
99
import { Omit } from "./util/omit";
1010
import { JsonapiResource, JsonapiResponseDoc, JsonapiResourceIdentifier } from "./jsonapi-spec";
1111
import { IncludeScopeHash } from "./util/include-directive";
12+
export declare type KeyCaseValue = "dash" | "camel" | "snake";
13+
export interface KeyCase {
14+
server: KeyCaseValue;
15+
client: KeyCaseValue;
16+
}
1217
export interface ModelConfiguration {
1318
baseUrl: string;
1419
apiNamespace: string;
1520
jsonapiType: string;
1621
endpoint: string;
1722
jwt: string;
1823
jwtStorage: string | false;
19-
camelizeKeys: boolean;
24+
keyCase: KeyCase;
2025
strictAttributes: boolean;
2126
logger: ILogger;
2227
}
@@ -57,7 +62,7 @@ export declare class JSORMBase {
5762
static endpoint: string;
5863
static isBaseClass: boolean;
5964
static jwt?: string;
60-
static camelizeKeys: boolean;
65+
static keyCase: KeyCase;
6166
static strictAttributes: boolean;
6267
static logger: ILogger;
6368
static sync: boolean;
@@ -89,6 +94,7 @@ export declare class JSORMBase {
8994
temp_id?: string;
9095
stale: boolean;
9196
storeKey: string;
97+
afterSync: (diff: Record<string, any>) => any | undefined;
9298
relationships: Record<string, JSORMBase | JSORMBase[]>;
9399
klass: typeof JSORMBase;
94100
private _persisted;
@@ -148,6 +154,8 @@ export declare class JSORMBase {
148154
static getJWT(): string | undefined;
149155
static generateAuthHeader(jwt: string): string;
150156
static getJWTOwner(): typeof JSORMBase | undefined;
157+
static serializeKey(key: string): string;
158+
static deserializeKey(key: string): string;
151159
destroy(): Promise<boolean>;
152160
save(options?: SaveOptions): Promise<boolean>;
153161
private _handleResponse(response, callback);

lib-esm/model.js

Lines changed: 45 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib-esm/model.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib-esm/request.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export declare class Request {
1111
constructor(middleware: MiddlewareStack, logger: ILogger);
1212
get(url: string, options: RequestInit): Promise<any>;
1313
post(url: string, payload: JsonapiRequestDoc, options: RequestInit): Promise<any>;
14-
put(url: string, payload: JsonapiRequestDoc, options: RequestInit): Promise<any>;
14+
patch(url: string, payload: JsonapiRequestDoc, options: RequestInit): Promise<any>;
1515
delete(url: string, options: RequestInit): Promise<any>;
1616
private _logRequest(verb, url);
1717
private _logResponse(responseJSON);

lib-esm/request.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)