@dhis2/app-service-data 3.3.0 → 3.4.2

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.
Files changed (38) hide show
  1. package/build/cjs/engine/helpers/getMutationFetchType.test.js +5 -0
  2. package/build/cjs/engine/helpers/validate.js +5 -1
  3. package/build/cjs/engine/helpers/validate.test.js +8 -0
  4. package/build/cjs/links/RestAPILink/queryToRequestOptions/requestContentType.js +5 -1
  5. package/build/cjs/links/RestAPILink/queryToRequestOptions/requestContentType.test.js +6 -0
  6. package/build/cjs/links/RestAPILink/queryToRequestOptions.js +4 -0
  7. package/build/cjs/links/RestAPILink/queryToRequestOptions.test.js +10 -0
  8. package/build/cjs/links/RestAPILink/queryToResourcePath.js +15 -2
  9. package/build/cjs/links/RestAPILink/queryToResourcePath.test.js +48 -15
  10. package/build/cjs/links/RestAPILink.js +9 -12
  11. package/build/cjs/react/hooks/mergeAndCompareVariables.js +33 -0
  12. package/build/cjs/react/hooks/mergeAndCompareVariables.test.js +57 -0
  13. package/build/cjs/react/hooks/useDataQuery.js +43 -53
  14. package/build/cjs/react/hooks/useDataQuery.test.js +59 -0
  15. package/build/cjs/react/hooks/useStaticInput.js +1 -0
  16. package/build/es/engine/helpers/getMutationFetchType.test.js +5 -0
  17. package/build/es/engine/helpers/validate.js +5 -1
  18. package/build/es/engine/helpers/validate.test.js +8 -0
  19. package/build/es/links/RestAPILink/queryToRequestOptions/requestContentType.js +5 -1
  20. package/build/es/links/RestAPILink/queryToRequestOptions/requestContentType.test.js +6 -0
  21. package/build/es/links/RestAPILink/queryToRequestOptions.js +4 -0
  22. package/build/es/links/RestAPILink/queryToRequestOptions.test.js +10 -0
  23. package/build/es/links/RestAPILink/queryToResourcePath.js +15 -2
  24. package/build/es/links/RestAPILink/queryToResourcePath.test.js +48 -15
  25. package/build/es/links/RestAPILink.js +9 -12
  26. package/build/es/react/hooks/mergeAndCompareVariables.js +23 -0
  27. package/build/es/react/hooks/mergeAndCompareVariables.test.js +53 -0
  28. package/build/es/react/hooks/useDataQuery.js +44 -54
  29. package/build/es/react/hooks/useDataQuery.test.js +59 -0
  30. package/build/es/react/hooks/useStaticInput.js +2 -1
  31. package/build/types/engine/types/ExecuteOptions.d.ts +1 -1
  32. package/build/types/engine/types/Mutation.d.ts +2 -2
  33. package/build/types/links/RestAPILink/queryToRequestOptions/requestContentType.d.ts +4 -6
  34. package/build/types/links/RestAPILink/queryToResourcePath.d.ts +2 -1
  35. package/build/types/links/RestAPILink.d.ts +5 -8
  36. package/build/types/react/hooks/mergeAndCompareVariables.d.ts +6 -0
  37. package/build/types/react/hooks/useDataQuery.d.ts +2 -2
  38. package/package.json +2 -2
@@ -1,10 +1,11 @@
1
- import { useState, useEffect, useRef } from 'react';
1
+ import { useState, useEffect, useRef, useDebugValue } from 'react';
2
2
  export const useStaticInput = (staticValue, {
3
3
  warn = false,
4
4
  name = 'input'
5
5
  } = {}) => {
6
6
  const originalValue = useRef(staticValue);
7
7
  const [value, setValue] = useState(() => originalValue.current);
8
+ useDebugValue(value, debugValue => "".concat(name, ": ").concat(JSON.stringify(debugValue)));
8
9
  useEffect(() => {
9
10
  if (warn && originalValue.current !== staticValue) {
10
11
  console.warn("The ".concat(name, " should be static, don't create it within the render loop!"));
@@ -1,6 +1,6 @@
1
1
  import { FetchError } from './FetchError';
2
2
  import { QueryVariables } from './Query';
3
- export declare type FetchType = 'create' | 'read' | 'update' | 'replace' | 'delete';
3
+ export declare type FetchType = 'create' | 'read' | 'update' | 'json-patch' | 'replace' | 'delete';
4
4
  export interface QueryExecuteOptions {
5
5
  variables?: QueryVariables;
6
6
  signal?: AbortSignal;
@@ -1,6 +1,6 @@
1
1
  import { FetchError } from './FetchError';
2
2
  import { ResourceQuery, QueryVariables } from './Query';
3
- export declare type MutationType = 'create' | 'update' | 'replace' | 'delete';
3
+ export declare type MutationType = 'create' | 'update' | 'json-patch' | 'replace' | 'delete';
4
4
  export interface MutationData {
5
5
  [key: string]: any;
6
6
  }
@@ -12,7 +12,7 @@ export interface CreateMutation extends BaseMutation {
12
12
  data: MutationData;
13
13
  }
14
14
  export interface UpdateMutation extends BaseMutation {
15
- type: 'update' | 'replace';
15
+ type: 'update' | 'replace' | 'json-patch';
16
16
  id: string;
17
17
  partial?: boolean;
18
18
  data: MutationData;
@@ -1,9 +1,7 @@
1
1
  import { ResolvedResourceQuery, FetchType } from '../../../engine';
2
- declare type RequestContentType = 'application/json' | 'text/plain' | 'multipart/form-data' | null;
2
+ declare type RequestContentType = 'application/json' | 'application/json-patch+json' | 'text/plain' | 'multipart/form-data' | null;
3
3
  export declare const FORM_DATA_ERROR_MSG = "Could not convert data to FormData: object does not have own enumerable string-keyed properties";
4
- export declare const requestContentType: (type: FetchType, query: ResolvedResourceQuery) => "application/json" | "text/plain" | "multipart/form-data" | null;
5
- export declare const requestHeadersForContentType: (contentType: RequestContentType) => {
6
- 'Content-Type': "application/json" | "text/plain";
7
- } | undefined;
8
- export declare const requestBodyForContentType: (contentType: RequestContentType, { data }: ResolvedResourceQuery) => any;
4
+ export declare const requestContentType: (type: FetchType, query: ResolvedResourceQuery) => null | RequestContentType;
5
+ export declare const requestHeadersForContentType: (contentType: RequestContentType) => undefined | Record<'Content-Type', string>;
6
+ export declare const requestBodyForContentType: (contentType: RequestContentType, { data }: ResolvedResourceQuery) => undefined | string | FormData;
9
7
  export {};
@@ -1,2 +1,3 @@
1
1
  import { ResolvedResourceQuery, FetchType } from '../../engine';
2
- export declare const queryToResourcePath: (apiPath: string, query: ResolvedResourceQuery, type: FetchType) => string;
2
+ import { RestAPILink } from '../RestAPILink';
3
+ export declare const queryToResourcePath: (link: RestAPILink, query: ResolvedResourceQuery, type: FetchType) => string;
@@ -1,13 +1,10 @@
1
+ import type { Config } from '@dhis2/app-service-config';
1
2
  import { DataEngineLink, DataEngineLinkExecuteOptions, FetchType, JsonValue, ResolvedResourceQuery } from '../engine/';
2
- export interface RestAPILinkInput {
3
- baseUrl: string;
4
- apiVersion: number;
5
- }
6
3
  export declare class RestAPILink implements DataEngineLink {
7
- private apiPath;
8
- private baseUrl;
9
- private apiVersion;
10
- constructor({ baseUrl, apiVersion }: RestAPILinkInput);
4
+ readonly config: Config;
5
+ readonly versionedApiPath: string;
6
+ readonly unversionedApiPath: string;
7
+ constructor(config: Config);
11
8
  private fetch;
12
9
  executeResourceQuery(type: FetchType, query: ResolvedResourceQuery, { signal }: DataEngineLinkExecuteOptions): Promise<JsonValue>;
13
10
  }
@@ -0,0 +1,6 @@
1
+ import type { QueryVariables } from '../../engine';
2
+ export declare const mergeAndCompareVariables: (previousVariables?: QueryVariables | undefined, newVariables?: QueryVariables | undefined, previousHash?: string | undefined) => {
3
+ identical: boolean;
4
+ mergedVariablesHash: string | undefined;
5
+ mergedVariables: QueryVariables | undefined;
6
+ };
@@ -1,3 +1,3 @@
1
- import { Query, QueryOptions } from '../../engine';
2
- import { QueryRenderInput } from '../../types';
1
+ import type { Query, QueryOptions } from '../../engine';
2
+ import type { QueryRenderInput } from '../../types';
3
3
  export declare const useDataQuery: (query: Query, { onComplete: userOnSuccess, onError: userOnError, variables: initialVariables, lazy: initialLazy, }?: QueryOptions) => QueryRenderInput;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhis2/app-service-data",
3
- "version": "3.3.0",
3
+ "version": "3.4.2",
4
4
  "main": "./build/cjs/index.js",
5
5
  "module": "./build/es/index.js",
6
6
  "types": "build/types/index.d.ts",
@@ -22,7 +22,7 @@
22
22
  "build/**"
23
23
  ],
24
24
  "peerDependencies": {
25
- "@dhis2/app-service-config": "3.3.0",
25
+ "@dhis2/app-service-config": "3.4.2",
26
26
  "@dhis2/cli-app-scripts": "^7.1.1",
27
27
  "prop-types": "^15.7.2",
28
28
  "react": "^16.8",